Skip to content

Commit 7b1a0ff

Browse files
committed
fix: Get Playground API_URL from window.location until provided explicitly in env. Remote server playground case.
1 parent 3376a50 commit 7b1a0ff

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

packages/cubejs-playground/src/ExplorePage.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* global window */
12
import React, { Component } from 'react';
23
import cubejs from '@cubejs-client/core';
34
import { fetch } from 'whatwg-fetch';
@@ -16,27 +17,31 @@ class ExplorePage extends Component {
1617
const result = await res.json();
1718
this.setState({
1819
cubejsToken: result.cubejsToken,
19-
apiUrl: result.apiUrl
20+
apiUrl: result.apiUrl || window.location.href.split('#')[0].replace(/\/$/, '')
2021
});
2122
}
2223

2324
cubejsApi() {
24-
if (!this.cubejsApiInstance && this.state.cubejsToken) {
25-
this.cubejsApiInstance = cubejs(this.state.cubejsToken, {
26-
apiUrl: this.state.apiUrl + '/cubejs-api/v1'
25+
const { cubejsToken, apiUrl } = this.state;
26+
if (!this.cubejsApiInstance && cubejsToken) {
27+
this.cubejsApiInstance = cubejs(cubejsToken, {
28+
apiUrl: `${apiUrl}/cubejs-api/v1`
2729
});
2830
}
2931
return this.cubejsApiInstance;
3032
}
3133

3234
render() {
33-
return this.cubejsApi() && (<PlaygroundQueryBuilder
34-
query={{}}
35-
cubejsApi={this.cubejsApi()}
36-
apiUrl={this.state.apiUrl}
37-
cubejsToken={this.state.cubejsToken}
38-
dashboardSource={this.dashboardSource}
39-
/>) || null;
35+
const { cubejsToken, apiUrl } = this.state;
36+
return this.cubejsApi() && (
37+
<PlaygroundQueryBuilder
38+
query={{}}
39+
cubejsApi={this.cubejsApi()}
40+
apiUrl={apiUrl}
41+
cubejsToken={cubejsToken}
42+
dashboardSource={this.dashboardSource}
43+
/>
44+
) || null;
4045
}
4146
}
4247

packages/cubejs-server-core/core/DevServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class DevServer {
4848
this.cubejsServer.event('Dev Server Env Open');
4949
res.json({
5050
cubejsToken: jwt.sign({}, this.cubejsServer.apiSecret, { expiresIn: '1d' }),
51-
apiUrl,
51+
apiUrl: process.env.CUBEJS_API_URL,
5252
anonymousId: this.cubejsServer.anonymousId
5353
});
5454
}));

0 commit comments

Comments
 (0)