feat: Integrate dynamic API key injection#1519
Open
willum070 wants to merge 10 commits into
Open
Conversation
5cab3a5 to
6bb2ce3
Compare
6bb2ce3 to
661cc25
Compare
07d1272 to
a037831
Compare
2e0f906 to
f988110
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR updates several processes to dynamically inject the production API key, as well as a newly added test API key for local development.
This PR does the following things:
1.
vite.config.js(Moved to Monorepo Root)enforce: 'pre') that intercepts all HTML, TS, and JS files during both local development (serve) and CI compilation (build). It hunts down the placeholder string"GOOGLE_MAPS_API_KEY"and securely swaps it out with the active environment variable in memory.dotenvto automatically load local development keys from the.envfile intoprocess.envwhen developers run the app locally.rootoverride, allowingrootto default toprocess.cwd(). This ensures Vite builds from the context of the active sample directory, fixing module resolution errors where React apps (react-ui-kit-*) were failing to find/src/app.tsx.[INVALID_OPTION]error by updatingrollupOptions.inputto use a simple string ('index') as the dictionary key rather than an absolute file path.2.
.github/workflows/release.ymlGOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}to the environment block of thenpm run build-allstep. This securely pipes the repository's production API key into the CI runner so the new Vite plugin can inject it into the finaldist/HTML artifacts.3.
.gitignore!samples/*/vite.config.js) to prevent the new local config stub files from being accidentally ignored by the legacysamples/*/*.jsrule (which was designed to ignore TypeScript compiler outputs).4.
dist.sh-Removes dist.sh: Removes this file since Vite now copies those files natively.
5.
.github/workflows/tests.yml:-Updates .github/workflows/tests.yml to inject a dedicated development API key (JS_MAPS_DEV) into the global environment variables specifically for the test runner. This was necessary since production keys will no longer allow local port restrictions.
6. All samples:
-Updates all sample projects to replace the production API key with a placeholder (GOOGLE_MAPS_API_KEY).
This architecture completely unifies how API keys are handled across all 80+ samples, eliminating hardcoded dummy strings in production while keeping the developer experience totally seamless!