-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify environment variables on frontend (#491)
- Loading branch information
1 parent
1c8b05c
commit 9aeda90
Showing
18 changed files
with
107 additions
and
129 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 |
---|---|---|
|
@@ -107,18 +107,18 @@ services: | |
- '80:80' # Change the first 80 to whatever port you want to access Retrospected from | ||
environment: | ||
# -- Optional -- | ||
GA_ID: '' # Optional, Google Analytics ID (UA-1234456-7) | ||
GOOGLE_AD_WORDS_ID: '' # Optional, Google Adwords ID (AW-1234456) | ||
GOOGLE_AD_WORDS_EVENT: '' # Optional, Google Adwords Event ID (AW-1234456/1234456) | ||
SENTRY_URL: '' # Optional, Sentry URL (https://[email protected]/1234567) | ||
GIPHY_API_KEY: '' # Optional, can be obtained here: https://developers.giphy.com/ | ||
DEFAULT_LANGUAGE: 'en-GB' # Set the default language for new users | ||
MARKETING_ROOT: 'https://www.retrospected.com' # URL of the marketing website | ||
FRONTEND_GOOGLE_ANALYTICS_ID: '' # Optional, Google Analytics ID (UA-1234456-7) | ||
FRONTEND_GOOGLE_AD_WORDS_ID: '' # Optional, Google Adwords ID (AW-1234456) | ||
FRONTEND_GOOGLE_AD_WORDS_CONVERSION_ID: '' # Optional, Google Adwords Event ID (AW-1234456/1234456) | ||
FRONTEND_SENTRY_URL: '' # Optional, Sentry URL (https://[email protected]/1234567) | ||
FRONTEND_GIPHY_API_KEY: '' # Optional, can be obtained here: https://developers.giphy.com/ | ||
FRONTEND_DEFAULT_LANGUAGE: 'en-GB' # Set the default language for new users | ||
FRONTEND_MARKETING_ROOT: 'https://www.retrospected.com' # URL of the marketing website | ||
|
||
# -- Do Not Change -- | ||
BACKEND_HOST: backend # This should be the name of the backend service | ||
BACKEND_PORT: 3201 # This should be the same as BACKEND_PORT on backend | ||
STRIPE_KEY: '' # Stripe publishable key (for frontend) | ||
FRONTEND_STRIPE_KEY: '' # Stripe publishable key (for frontend) | ||
|
||
restart: unless-stopped | ||
logging: | ||
|
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 |
---|---|---|
@@ -1 +1,7 @@ | ||
VITE_VERSION=$npm_package_version | ||
VITE_STRIPE_KEY= | ||
VITE_GIPHY_API_KEY= | ||
VITE_MARKETING_ROOT=http://localhost:3001 | ||
VITE_GOOGLE_ANALYTICS_ID= | ||
VITE_GOOGLE_AD_WORDS_ID= | ||
VITE_GOOGLE_AD_WORDS_CONVERSION_ID= |
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 |
---|---|---|
@@ -1,18 +1,28 @@ | ||
#!/usr/bin/env sh | ||
set -eu | ||
|
||
# Configure Nginx with backend host and port | ||
BACKEND_HOST="${BACKEND_HOST:-backend}" \ | ||
BACKEND_PORT="${BACKEND_PORT:-3201}" \ | ||
envsubst '${BACKEND_HOST} ${BACKEND_PORT}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf | ||
|
||
# Replacing Google Analytics and Sentry IDs. Separator is # because the sentry URL contains a / | ||
sed -i "s#NO_GA#${GA_ID:-}#g" /usr/share/nginx/html/index.html | ||
sed -i "s#NO_AD_WORDS_ID#${GOOGLE_AD_WORDS_ID:-}#g" /usr/share/nginx/html/index.html | ||
sed -i "s#NO_AD_WORDS_EVENT#${GOOGLE_AD_WORDS_EVENT:-}#g" /usr/share/nginx/html/index.html | ||
sed -i "s#NO_SENTRY#${SENTRY_URL:-}#g" /usr/share/nginx/html/index.html | ||
sed -i "s#NO_GIPHY#${GIPHY_API_KEY:-}#g" /usr/share/nginx/html/index.html | ||
sed -i "s#NO_STRIPE#${STRIPE_KEY:-}#g" /usr/share/nginx/html/index.html | ||
sed -i "s#NO_DEFAULT_LANGUAGE#${DEFAULT_LANGUAGE:-en-GB}#g" /usr/share/nginx/html/index.html | ||
sed -i "s#NO_MARKETING_ROOT#${MARKETING_ROOT:-https://www.retrospected.com}#g" /usr/share/nginx/html/index.html | ||
# Configure the frontend with environment variables | ||
CONFIG_FILE='/usr/share/nginx/html/config.tmp' | ||
HTML_FILE='/usr/share/nginx/html/index.html' | ||
PREFIX='FRONTEND_' | ||
|
||
exec "$@" | ||
# Creates a file with the environment variables that start with FRONTEND_ | ||
echo " window.__env__ = {" > "${CONFIG_FILE}" | ||
jq -n 'env' | { grep "\"$PREFIX" || true; }>> "${CONFIG_FILE}" | ||
echo " };" >> "${CONFIG_FILE}" | ||
|
||
# Removes the prefix from the environment variables | ||
sed -i "s#\"${PREFIX}# \"#g" "${CONFIG_FILE}" | ||
|
||
# Injects the configuration file into the HTML file | ||
sed -i -e "/RUN-TIME CONFIGURATION/r ${CONFIG_FILE}" ${HTML_FILE} | ||
|
||
# Removes the temporary configuration file | ||
rm $CONFIG_FILE | ||
|
||
exec "$@" |
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
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
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
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
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
Oops, something went wrong.