-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runtime environment variables in React
- Loading branch information
1 parent
81cd2ae
commit 1212642
Showing
5 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM node as builder | ||
WORKDIR /ui | ||
COPY package.json package-lock.json /ui/ | ||
# src/api contains Swagger-generated data_explorer_service. This is needed by | ||
# "npm install" beacuse package.json has a local dependency on | ||
# data_explorer_service. | ||
COPY src/api /ui/src/api | ||
RUN npm install | ||
RUN npm install react-scripts@1.1.1 -g | ||
COPY . /ui | ||
RUN npm run build | ||
|
||
ENV API_URL foo | ||
|
||
FROM nginx | ||
COPY --from=builder /ui/build /usr/share/nginx/html | ||
CMD sed -i "s/API_URL_REPLACE_ME/$API_URL/" /usr/share/nginx/html/env.js && nginx -g "daemon off;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Create React App doesn't have an easy way to set run-time environment | ||
// variables. Here we copy | ||
// https://github.com/facebook/create-react-app/issues/578#issuecomment-277843310 | ||
|
||
window.env = { | ||
// This option can be retrieved in "src/index.js" with "window.env.API_URL". | ||
API_URL: 'API_URL_REPLACE_ME' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters