Skip to content

Commit

Permalink
fix(env): inject all exported env vars into index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
oyo committed Oct 11, 2024
1 parent f730ea6 commit c595c02
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
<body>
<div id="app"></div>
<script>

// Do NOT change ENV attributes without changing them in scripts/inject-dynamic-env.sh as well
const ENV = {
REQUIRE_HTTPS_URL_PATTERN: "true",
CLEARINGHOUSE_CONNECT_DISABLED: "false",
PORTAL_ASSETS_URL: "http://localhost:3000/assets",
PORTAL_BACKEND_URL: "https://portal-backend.example.org",
CENTRALIDP_URL: "https://centralidp.example.org/auth",
Expand Down
4 changes: 4 additions & 0 deletions scripts/inject-dynamic-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
source_file=/usr/share/nginx/html/index.html.reference
target_file=/tmp/index.html

# these environment variables should be set and match the ones in index.html
# sequence is irrelevant
vars=" \
REQUIRE_HTTPS_URL_PATTERN \
CLEARINGHOUSE_CONNECT_DISABLED \
CENTRALIDP_URL \
PORTAL_ASSETS_URL \
PORTAL_BACKEND_URL \
Expand Down Expand Up @@ -52,4 +55,5 @@ while [ -n "$1" ]; do
shift
done

# execute the built replace command and write to target file
echo ${sed_command} | sh > ${target_file}
5 changes: 4 additions & 1 deletion src/services/EnvironmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

declare const ENV: Record<string, string>

// get the value of REQUIRE_HTTPS_URL_PATTERN environment variable, defaulting to 'true' if not set
export const getRequireHttpsUrlPattern = () =>
ENV.REQUIRE_HTTPS_URL_PATTERN ?? 'true'

export const getClearinghouseConnectDisabled = () =>
ENV.CLEARINGHOUSE_CONNECT_DISABLED ?? 'false'

export const getRealm = () => ENV.REALM ?? ''

export const getClientId = () => ENV.CLIENT_ID ?? ''
Expand Down Expand Up @@ -57,6 +59,7 @@ export const getSSICredentialBase = () => ENV.SSI_CREDENTIAL_URL ?? ''

const EnvironmentService = {
getRequireHttpsUrlPattern,
getClearinghouseConnectDisabled,
getRealm,
getClientId,
getClientIdRegistration,
Expand Down

0 comments on commit c595c02

Please sign in to comment.