-
Notifications
You must be signed in to change notification settings - Fork 17
46741 frontend [ Configuration ] Migrate Frontend to Runtime Environment Variables #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
EBirkenfeld
merged 12 commits into
master
from
frontend/configuration/46741__migrate_frontend_to_runtime_environment
May 29, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7a5601a
46741 feat(frontend): migrate environment variables to runtime config
EBirkenfeld 32ee3bf
46741 fix(frontend): remove secrets from browser config and fix Fireb…
EBirkenfeld 5e83ad0
46741 fix(docker): add COPY instruction to backend Dockerfile for Rai…
EBirkenfeld 9fd988f
46741 refactor(frontend): remove dead MCS_RUN_ENV from webpack config
EBirkenfeld 6774e89
46741 fix(frontend): use correct RECAPTCHA_SITE_KEY env var in featur…
EBirkenfeld 68bd216
46741 refactor(frontend): remove dead Sentry webpack plugin and fix d…
EBirkenfeld 769e521
46741 refactor(frontend): improve type safety and add tests for env c…
EBirkenfeld 58883a0
46741 refactor(frontend): apply code review fixes for runtime env mig…
EBirkenfeld 6323286
46741 fix(firebase): revert env key to FIREBASE_MESSAGING_SENDER_ID
EBirkenfeld ca4499b
Revert "46741 fix(firebase): revert env key to FIREBASE_MESSAGING_SEN…
EBirkenfeld 7723849
46741 chore(frontend): use explicit npm script for client build
EBirkenfeld 3cfe1dc
46741 fix(frontend): add NODE_OPTIONS to Dockerfile for webpack build…
EBirkenfeld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -172,6 +172,7 @@ | |
| "mainPage", | ||
| "formSubdomain", | ||
| "recaptchaSecret", | ||
| "firebase" | ||
| "firebase", | ||
| "featureFlags" | ||
| ] | ||
| } | ||
This file contains hidden or 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,159 @@ | ||
| // <reference types="jest" /> | ||
|
|
||
| /** | ||
| * Tests for webpack.config.js behavioral changes: | ||
| * 1. No dotenv — .env is not read at build time | ||
| * 2. No envKeys — process.env is not forwarded to bundle | ||
| * 3. DefinePlugin only sets process.env.NODE_ENV | ||
| * 4. No MCS_RUN_ENV in HtmlWebpackPlugin | ||
| * 5. No Sentry webpack plugin | ||
| */ | ||
|
|
||
| jest.mock('mini-css-extract-plugin', () => { | ||
| class MiniCssExtractPlugin { | ||
| static loader = {}; | ||
| } | ||
| return MiniCssExtractPlugin; | ||
| }); | ||
|
|
||
| jest.mock('fork-ts-checker-webpack-plugin', () => { | ||
| return class ForkTsCheckerWebpackPlugin {}; | ||
| }); | ||
|
|
||
| jest.mock('html-webpack-plugin', () => { | ||
| return class HtmlWebpackPlugin { | ||
| public options: Record<string, unknown>; | ||
| constructor(options: Record<string, unknown>) { | ||
| this.options = options; | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| interface IWebpackPlugin { | ||
| constructor: { name: string }; | ||
| definitions?: Record<string, string>; | ||
| options?: Record<string, unknown> & { authToken?: string; filename?: string }; | ||
| } | ||
|
|
||
| describe('webpack.config.js', () => { | ||
| const ORIGINAL_ENV = process.env; | ||
|
|
||
| beforeEach(() => { | ||
| jest.resetModules(); | ||
| process.env = { ...ORIGINAL_ENV }; | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| process.env = ORIGINAL_ENV; | ||
| }); | ||
|
|
||
| const loadConfig = (envOverrides: Record<string, string> = {}) => { | ||
| Object.assign(process.env, envOverrides); | ||
| return require('../../webpack.config.js') as { plugins: IWebpackPlugin[]; entry: unknown; mode: string; devtool: string }; | ||
| }; | ||
|
|
||
| describe('DefinePlugin configuration', () => { | ||
| it('defines process.env.NODE_ENV via DefinePlugin (not full process.env)', () => { | ||
| process.env.NODE_ENV = 'production'; | ||
| const config = loadConfig({ NODE_ENV: 'production' }); | ||
|
|
||
| const definePlugin = config.plugins.find( | ||
| (p: IWebpackPlugin) => p.constructor.name === 'DefinePlugin', | ||
| ); | ||
|
|
||
| expect(definePlugin).toBeDefined(); | ||
| expect(definePlugin!.definitions).toEqual({ | ||
| 'process.env.NODE_ENV': '"production"', | ||
| }); | ||
| }); | ||
|
|
||
| it('does not forward arbitrary env vars to the bundle', () => { | ||
| const config = loadConfig({ | ||
| NODE_ENV: 'development', | ||
| SECRET_KEY: 'should-not-be-in-bundle', | ||
| BACKEND_URL: 'https://example.com', | ||
| }); | ||
|
|
||
| const definePlugin = config.plugins.find( | ||
| (p: IWebpackPlugin) => p.constructor.name === 'DefinePlugin', | ||
| ); | ||
|
|
||
| expect(definePlugin!.definitions).not.toHaveProperty('process.env'); | ||
| const definedKeys = Object.keys(definePlugin!.definitions!); | ||
| expect(definedKeys).not.toContain('process.env'); | ||
| expect(definedKeys).toEqual(['process.env.NODE_ENV']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('HtmlWebpackPlugin configuration', () => { | ||
| it('main template does not have mcsRunEnv property', () => { | ||
| const config = loadConfig({ NODE_ENV: 'production' }); | ||
|
|
||
| const htmlPlugins = config.plugins.filter( | ||
| (p: IWebpackPlugin) => p.constructor.name === 'HtmlWebpackPlugin', | ||
| ); | ||
|
|
||
| const mainPlugin = htmlPlugins.find((p: IWebpackPlugin) => p.options?.filename === 'main.ejs'); | ||
| expect(mainPlugin).toBeDefined(); | ||
| expect(mainPlugin!.options).not.toHaveProperty('mcsRunEnv'); | ||
| }); | ||
|
|
||
| it('forms template does not have mcsRunEnv property', () => { | ||
| const config = loadConfig({ NODE_ENV: 'production' }); | ||
|
|
||
| const htmlPlugins = config.plugins.filter( | ||
| (p: IWebpackPlugin) => p.constructor.name === 'HtmlWebpackPlugin', | ||
| ); | ||
|
|
||
| const formsPlugin = htmlPlugins.find((p: IWebpackPlugin) => p.options?.filename === 'forms.ejs'); | ||
| expect(formsPlugin).toBeDefined(); | ||
| expect(formsPlugin!.options).not.toHaveProperty('mcsRunEnv'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Sentry webpack plugin removal', () => { | ||
| it('does not include sentryWebpackPlugin even when SENTRY_AUTH_TOKEN is set', () => { | ||
| const config = loadConfig({ | ||
| NODE_ENV: 'production', | ||
| SENTRY_AUTH_TOKEN: 'fake-token', | ||
| SENTRY_RELEASE: 'v1.0.0', | ||
| SENTRY_ORG: 'test-org', | ||
| SENTRY_PROJECT: 'test-project', | ||
| }); | ||
|
|
||
| const pluginNames = config.plugins.map((p: IWebpackPlugin) => p.constructor.name); | ||
| expect(pluginNames).not.toContain('sentryWebpackPlugin'); | ||
|
|
||
| const hasSentryPlugin = config.plugins.some( | ||
| (p: IWebpackPlugin) => | ||
| p.constructor.name.toLowerCase().includes('sentry') || | ||
| (p.options && p.options.authToken), | ||
| ); | ||
| expect(hasSentryPlugin).toBe(false); | ||
| }); | ||
|
EBirkenfeld marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| describe('dotenv removal', () => { | ||
| it('does not require dotenv module', () => { | ||
| const config = loadConfig({ NODE_ENV: 'production' }); | ||
|
|
||
| // Config should load successfully without a .env file | ||
| expect(config).toBeDefined(); | ||
| expect(config.entry).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('mode and devtool', () => { | ||
| it('sets mode to production when NODE_ENV is production', () => { | ||
| const config = loadConfig({ NODE_ENV: 'production' }); | ||
|
|
||
| expect(config.mode).toBe('production'); | ||
| }); | ||
|
|
||
| it('sets mode to development when NODE_ENV is development', () => { | ||
| const config = loadConfig({ NODE_ENV: 'development' }); | ||
|
|
||
| expect(config.mode).toBe('development'); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.