diff --git a/console/README.md b/console/README.md index 2022be1105bab..df1bd05152573 100644 --- a/console/README.md +++ b/console/README.md @@ -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 diff --git a/console/src/Globals.js b/console/src/Globals.js index 0ee534d3a89ee..5a33109441a11 100644 --- a/console/src/Globals.js +++ b/console/src/Globals.js @@ -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) { + 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