From 06a1f6a1c112cb2b79ee9f3a1fa670a579eb479b Mon Sep 17 00:00:00 2001 From: wawhal Date: Tue, 18 Dec 2018 17:45:15 +0530 Subject: [PATCH 1/2] console determines data api url from console path --- console/src/Globals.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 From 26dbe20fc043cc4ef654e860350c46defc03d58a Mon Sep 17 00:00:00 2001 From: wawhal Date: Wed, 19 Dec 2018 18:57:10 +0530 Subject: [PATCH 2/2] update contributing instructions in README --- console/README.md | 2 ++ 1 file changed, 2 insertions(+) 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