Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

determine api root from consolepath var on console #1228

Merged
merged 3 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Environment variables accepted in `server` mode:
5. `CONSOLE_MODE`: `server`
6. `URL_PREFIX`: `/` (forward slash)

> The server also templates `consolePath` in `window.__env` which is the relative path of the current page (something like `/console/data/schema/public`). Using this path, the console determines the DATA_API_URL. You do not need to worry about this in development since you are hardcoding the value of DATA_API_URL in `.env`.

#### Run Development Server:

```bash
Expand Down
18 changes: 16 additions & 2 deletions console/src/Globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,22 @@ if (

if (globals.consoleMode === SERVER_CONSOLE_MODE) {
if (globals.nodeEnv !== 'development') {
const windowUrl = window.location.protocol + '//' + window.location.host;
globals.dataApiUrl = windowUrl;
if (window.__env.consolePath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this env in helpers/Html.js

const safeCurrentUrl = checkExtraSlashes(window.location.href);
globals.dataApiUrl = safeCurrentUrl.slice(
0,
safeCurrentUrl.lastIndexOf(window.__env.consolePath)
);
const currentPath = checkExtraSlashes(window.location.pathname);
globals.urlPrefix =
currentPath.slice(
0,
currentPath.lastIndexOf(window.__env.consolePath)
) + '/console';
} else {
const windowUrl = window.location.protocol + '//' + window.location.host;
globals.dataApiUrl = windowUrl;
}
}
/*
* Require the exact usecase
Expand Down