diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-10-27 20:30:09 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-10-27 21:25:06 +0100 |
| commit | 70026cebc0fd20b660cafe0bf95d0eea73459de2 (patch) | |
| tree | fe8860bdfebfc01c386c72818b448d507e8a1dfc /frontend | |
| parent | 045a195366c03eb259669099a21adbf2c6754da1 (diff) | |
Propagate user-specified API url to React build
This change fixes an issue where we did not forward the environmental
variable for controlling the API url to the React build.
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/Dockerfile | 6 | ||||
| -rw-r--r-- | frontend/src/api/routes/token-signin.js | 9 | ||||
| -rw-r--r-- | frontend/src/api/socket.js | 2 |
3 files changed, 12 insertions, 5 deletions
diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 36e3c20b..113b09c9 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,7 +1,8 @@ FROM node:14 MAINTAINER OpenDC Maintainers <opendc@atlarge-research.com> -ARG REACT_APP_OAUTH_CLIENT_ID +ARG OPENDC_OAUTH_CLIENT_ID +ARG OPENDC_API_BASE_URL # Copy OpenDC directory COPY ./ /opendc @@ -10,7 +11,8 @@ COPY ./ /opendc RUN cd /opendc/ \ && rm -rf ./build \ && yarn \ - && export REACT_APP_OAUTH_CLIENT_ID=$REACT_APP_OAUTH_CLIENT_ID \ + && export REACT_APP_OAUTH_CLIENT_ID=$OPENDC_OAUTH_CLIENT_ID \ + && export REACT_APP_API_BASE_URL=$OPENDC_API_BASE_URL \ && yarn build # Setup nginx to serve the frontend diff --git a/frontend/src/api/routes/token-signin.js b/frontend/src/api/routes/token-signin.js index 7553d043..577f4723 100644 --- a/frontend/src/api/routes/token-signin.js +++ b/frontend/src/api/routes/token-signin.js @@ -1,5 +1,10 @@ export function performTokenSignIn(token) { - return new Promise((resolve) => { - window['jQuery'].post('/tokensignin', { idtoken: token }, (data) => resolve(data)) + const apiUrl = process.env.REACT_APP_API_BASE_URL || '' + const data = new FormData() + data.append('idtoken', token) + + return fetch(`https://${apiUrl}/tokensignin`, { + method: 'POST', + body: data, }) } diff --git a/frontend/src/api/socket.js b/frontend/src/api/socket.js index 96034021..6974d5eb 100644 --- a/frontend/src/api/socket.js +++ b/frontend/src/api/socket.js @@ -6,7 +6,7 @@ let requestIdCounter = 0 const callbacks = {} export function setupSocketConnection(onConnect) { - const apiUrl = process.env.REACT_APP_API_URL || window.location.hostname + ':' + window.location.port + const apiUrl = process.env.REACT_APP_API_BASE_URL || window.location.hostname + ':' + window.location.port socket = io.connect(window.location.protocol + '//' + apiUrl) socket.on('connect', onConnect) |
