Skip to content

Commit 64e4fa8

Browse files
committed
chore: new server compatible with dynamic runtime envs Refs: PL-240
1 parent 139b483 commit 64e4fa8

1 file changed

Lines changed: 8 additions & 22 deletions

File tree

server.mjs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,14 @@ const injectHtml = ({
8787
customValues,
8888
nonce,
8989
}) => {
90-
const nodeEnvLines = [
91-
'window.nodeEnvSettings = {};',
92-
...Object.keys(process.env)
93-
.filter((key) => key.startsWith('REACT_APP_'))
94-
.map((key) => {
95-
const value = process.env[ key ];
96-
if (value !== undefined && value !== null && value !== '' && value !== 'undefined') {
97-
return `window.nodeEnvSettings.${key} = ${JSON.stringify(value)};`;
98-
}
99-
return '';
100-
})
101-
.filter(Boolean),
102-
process.env.MODE !== undefined
103-
? `window.nodeEnvSettings.MODE = ${JSON.stringify(process.env.MODE)};`
104-
: '',
105-
`window.nodeEnvSettings.REACT_APP_INITIAL_MAP_POSITION = ${JSON.stringify(customValues.initialMapPosition)};`,
106-
`window.nodeEnvSettings.appVersion = { tag: ${JSON.stringify(GIT_TAG)}, commit: ${JSON.stringify(GIT_COMMIT)} };`,
90+
// Patch the request-specific map position into window._env_ (populated by env-config.js),
91+
// then expose the Redux store for client-side hydration.
92+
const inlineScript = [
93+
`if (window._env_) {`,
94+
` window._env_.REACT_APP_INITIAL_MAP_POSITION = ${JSON.stringify(customValues.initialMapPosition)};`,
95+
`}`,
10796
`window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(/</g, '\\u003c')};`,
108-
]
109-
.filter(Boolean)
110-
.join('\n ');
97+
].join('\n ');
11198

11299
const readSpeakerScript =
113100
process.env.REACT_APP_READ_SPEAKER_URL &&
@@ -132,9 +119,8 @@ const injectHtml = ({
132119
</style>
133120
<meta name="viewport" content="width=device-width, initial-scale=1">
134121
<meta name="theme-color" content="#141823" />
135-
<script src="/env-config.js" nonce="${nonce}"></script>
136122
${readSpeakerScript}
137-
<script nonce="${nonce}">${nodeEnvLines}</script>`;
123+
<script nonce="${nonce}">${inlineScript}</script>`;
138124

139125
return template
140126
.replace(/lang="[^"]*"/, `lang="${locale || 'fi'}"`)

0 commit comments

Comments
 (0)