(SP: 1) [FIX] Fix Netlify SSR runtime env vars for develop deploy#425
(SP: 1) [FIX] Fix Netlify SSR runtime env vars for develop deploy#425ViktorSvertoka merged 5 commits intodevelopfrom
Conversation
fix(about): update LinkedIn follower fallback to 1800
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
📝 WalkthroughWalkthroughThis pull request relaxes Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (4)
frontend/vitest.shop.config.ts (1)
16-18: Same formatting inconsistency asvitest.config.ts.The
envblock indentation is misaligned with sibling properties.🔧 Suggested fix
test: { - env: { - APP_ENV: 'local', - }, + env: { + APP_ENV: 'local', + }, environment: 'node',🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/vitest.shop.config.ts` around lines 16 - 18, The env block in frontend/vitest.shop.config.ts is misindented compared to sibling properties; fix the indentation of the env object (the APP_ENV property) so it lines up with other top-level keys in the config (match the formatting used in vitest.config.ts), ensuring consistent spacing and alignment for the env: { APP_ENV: 'local' } block.frontend/db/index.ts (1)
82-85: Clarify error message whenAPP_ENVis undefined.When
APP_ENVis unset,IS_LOCAL_ENVisfalse, so this branch executes. The error message interpolatesAPP_ENVwhich would show"APP_ENV=undefined requires DATABASE_URL"— this could be confusing for debugging.💡 Suggested improvement
if (!url) { throw new Error( - `[db] APP_ENV=${APP_ENV} requires DATABASE_URL to be set` + `[db] APP_ENV=${APP_ENV ?? '<undefined>'} requires DATABASE_URL to be set` ); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/db/index.ts` around lines 82 - 85, The error thrown when DATABASE_URL is missing interpolates APP_ENV which may be undefined and confusing; update the throw in frontend/db/index.ts to produce a clear message by checking APP_ENV (and/or IS_LOCAL_ENV) and printing a readable value like "unset" or "unknown" (e.g., use APP_ENV ?? 'unset') and include context that DATABASE_URL is missing and whether IS_LOCAL_ENV is true/false; change the throw new Error(...) around the url check to use this clarified message referencing APP_ENV and IS_LOCAL_ENV.frontend/vitest.config.ts (1)
16-18: Minor formatting inconsistency.The
envblock indentation appears misaligned compared to sibling properties likeenvironmentandinclude. This may cause linter warnings.🔧 Suggested fix
test: { - env: { - APP_ENV: 'local', - }, + env: { + APP_ENV: 'local', + }, environment: 'node',🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/vitest.config.ts` around lines 16 - 18, The env block in vitest.config.ts is misindented relative to sibling properties (e.g., environment and include); fix by aligning the env property and its inner APP_ENV line with the same indentation level used for environment and include so the object properties are consistently formatted (look for the env: { APP_ENV: 'local', } block and adjust spacing to match the surrounding configuration entries).frontend/next.config.ts (1)
8-11: Refactor to useserverRuntimeConfigfor server-only secrets.The
envblock exposesDATABASE_URLto both server and client code paths. While no client code currently referencesprocess.env.DATABASE_URL, this pattern is fragile — someone could accidentally add a client-side reference and expose the connection string. Server-only secrets should useserverRuntimeConfiginstead:const nextConfig: NextConfig = { serverRuntimeConfig: { DATABASE_URL: process.env.DATABASE_URL, }, publicRuntimeConfig: { APP_ENV: process.env.APP_ENV, }, // ... };Then access as
getServerSidePropsorgetConfig().serverRuntimeConfig.DATABASE_URLon the server, keeping it unreachable from client bundles.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/next.config.ts` around lines 8 - 11, The current next.config.ts exposes DATABASE_URL via the env block; change the NextConfig export to move DATABASE_URL into serverRuntimeConfig and put APP_ENV into publicRuntimeConfig (i.e., replace the env object with serverRuntimeConfig: { DATABASE_URL: process.env.DATABASE_URL } and publicRuntimeConfig: { APP_ENV: process.env.APP_ENV }), then update server-side access patterns to read the secret from getConfig().serverRuntimeConfig.DATABASE_URL or within getServerSideProps rather than from process.env in client-safe code; ensure no client bundle imports process.env.DATABASE_URL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@frontend/db/index.ts`:
- Around line 82-85: The error thrown when DATABASE_URL is missing interpolates
APP_ENV which may be undefined and confusing; update the throw in
frontend/db/index.ts to produce a clear message by checking APP_ENV (and/or
IS_LOCAL_ENV) and printing a readable value like "unset" or "unknown" (e.g., use
APP_ENV ?? 'unset') and include context that DATABASE_URL is missing and whether
IS_LOCAL_ENV is true/false; change the throw new Error(...) around the url check
to use this clarified message referencing APP_ENV and IS_LOCAL_ENV.
In `@frontend/next.config.ts`:
- Around line 8-11: The current next.config.ts exposes DATABASE_URL via the env
block; change the NextConfig export to move DATABASE_URL into
serverRuntimeConfig and put APP_ENV into publicRuntimeConfig (i.e., replace the
env object with serverRuntimeConfig: { DATABASE_URL: process.env.DATABASE_URL }
and publicRuntimeConfig: { APP_ENV: process.env.APP_ENV }), then update
server-side access patterns to read the secret from
getConfig().serverRuntimeConfig.DATABASE_URL or within getServerSideProps rather
than from process.env in client-safe code; ensure no client bundle imports
process.env.DATABASE_URL.
In `@frontend/vitest.config.ts`:
- Around line 16-18: The env block in vitest.config.ts is misindented relative
to sibling properties (e.g., environment and include); fix by aligning the env
property and its inner APP_ENV line with the same indentation level used for
environment and include so the object properties are consistently formatted
(look for the env: { APP_ENV: 'local', } block and adjust spacing to match the
surrounding configuration entries).
In `@frontend/vitest.shop.config.ts`:
- Around line 16-18: The env block in frontend/vitest.shop.config.ts is
misindented compared to sibling properties; fix the indentation of the env
object (the APP_ENV property) so it lines up with other top-level keys in the
config (match the formatting used in vitest.config.ts), ensuring consistent
spacing and alignment for the env: { APP_ENV: 'local' } block.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d120a427-f439-4db9-af7b-c31bbc414347
📒 Files selected for processing (6)
frontend/db/index.tsfrontend/db/queries/categories/admin-categories.tsfrontend/next.config.tsfrontend/vitest.config.tsfrontend/vitest.shop.config.tsnetlify.toml
💤 Files with no reviewable changes (1)
- netlify.toml
Goal
Fix Netlify develop deploy crash where SSR runtime does not receive env vars from dashboard despite correct configuration (All scopes, all contexts).
Scope
node_bundler = "esbuild"fromnetlify.toml— conflicted with@netlify/plugin-nextjsown bundling, potentially breaking env var injectionenvblock innext.config.tsto inlineAPP_ENVandDATABASE_URLat build time — ensures values are available in SSR runtime regardless of platform env deliveryExpected impact
All 28 SSR pages that depend on
@/dbshould stop crashing on Netlify develop deploy. Blog categories in header remain disabled (separate follow-up).Out of scope
_dev-notes/blog-header-hardcode-plan.mdSummary by CodeRabbit
Bug Fixes
Tests
Chores