fix(netlify): deliver env vars to SSR runtime via .env generation at build time#428
fix(netlify): deliver env vars to SSR runtime via .env generation at build time#428ViktorSvertoka merged 12 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
|
📝 WalkthroughWalkthroughFixed a stray leading character causing a parse error in Changes
Sequence Diagram(s)(omitted — changes are small and do not introduce multi-component sequential control flow needing visualization) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@netlify.toml`:
- Line 3: Replace the unsafe "printenv > .env" step with an explicit
allowlist-based .env generation: remove the "printenv > .env" command and
instead run a small script or npm script that reads a whitelist sourced from
frontend/.env.example and writes only those variables into .env (or rely on
Netlify's native env management), ensuring multiline values are handled
correctly and sensitive/platform vars are not dumped; update the command string
(currently containing "printenv > .env") to call that script or drop the
generation step when using Netlify UI/API-managed variables.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 41283cff-9955-4bc0-9e12-4c550d2f5f89
📒 Files selected for processing (2)
frontend/db/index.tsnetlify.toml
There was a problem hiding this comment.
🧹 Nitpick comments (2)
frontend/scripts/generate-env.sh (2)
1-7: Consider addingset -efor fail-fast behavior.If
.env.exampleis missing or unreadable, the script will silently create an empty.env, which could mask configuration errors during deployment.🛡️ Proposed fix
#!/usr/bin/env bash +set -e # Generate .env from .env.example allowlist using current environment. # Only variables listed in .env.example are included — no platform internals leak.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/scripts/generate-env.sh` around lines 1 - 7, The script can silently produce an empty .env if .env.example is missing or unreadable; add fail-fast behavior by enabling errexit at the top (e.g., add set -e) and validate .env.example is readable before the grep loop (check and error out if not), updating the generate-env.sh header and the beginning of the logic that uses grep/cut/while read -r var so the script exits immediately on failures instead of creating an empty .env.
4-6: Values with special characters may produce malformed.enventries.If an environment variable value contains newlines, unescaped quotes, or other special characters, the resulting
.envline could be invalid. Quoting values provides safer output for most.envparsers.♻️ Proposed fix with quoted values
grep '^[A-Z]' .env.example | cut -d= -f1 | while read -r var; do val="${!var}" - [ -n "$val" ] && printf '%s=%s\n' "$var" "$val" + [ -n "$val" ] && printf '%s="%s"\n' "$var" "$val" done > .envNote: If values could contain double quotes themselves, you'd need to escape them (e.g.,
${val//\"/\\\"}), but this is typically uncommon for standard env vars.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/scripts/generate-env.sh` around lines 4 - 6, The loop that reads variable names (var) and prints raw values (val) can produce malformed .env entries for values with newlines or quotes; update the while-read loop that builds lines for each var so it emits quoted values and escapes any embedded double quotes and newlines before printing (i.e., transform val by escaping " to \" and converting literal newlines to \n) and then output as VAR="escaped_value" to ensure generated .env entries remain valid for common parsers.
🤖 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/scripts/generate-env.sh`:
- Around line 1-7: The script can silently produce an empty .env if .env.example
is missing or unreadable; add fail-fast behavior by enabling errexit at the top
(e.g., add set -e) and validate .env.example is readable before the grep loop
(check and error out if not), updating the generate-env.sh header and the
beginning of the logic that uses grep/cut/while read -r var so the script exits
immediately on failures instead of creating an empty .env.
- Around line 4-6: The loop that reads variable names (var) and prints raw
values (val) can produce malformed .env entries for values with newlines or
quotes; update the while-read loop that builds lines for each var so it emits
quoted values and escapes any embedded double quotes and newlines before
printing (i.e., transform val by escaping " to \" and converting literal
newlines to \n) and then output as VAR="escaped_value" to ensure generated .env
entries remain valid for common parsers.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 70e2afa5-00bc-484f-b87f-35ed5fc4bae5
📒 Files selected for processing (2)
frontend/scripts/generate-env.shnetlify.toml
🚧 Files skipped from review as they are similar to previous changes (1)
- netlify.toml
fix(netlify): deliver env vars to SSR runtime via .env generation at build time
Summary by CodeRabbit
Bug Fixes
Chores