Skip to content

fix(netlify): deliver env vars to SSR runtime via .env generation at build time#428

Merged
ViktorSvertoka merged 12 commits intodevelopfrom
sl/feat/db-optimization
Mar 28, 2026
Merged

fix(netlify): deliver env vars to SSR runtime via .env generation at build time#428
ViktorSvertoka merged 12 commits intodevelopfrom
sl/feat/db-optimization

Conversation

@LesiaUKR
Copy link
Copy Markdown
Collaborator

@LesiaUKR LesiaUKR commented Mar 28, 2026

fix(netlify): deliver env vars to SSR runtime via .env generation at build time

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a syntax error causing a runtime issue.
  • Chores

    • Added an automated script to generate a .env from the example during build.
    • Updated deployment build process to run env generation and simplified build plugin configuration.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
devlovers-net Ignored Ignored Preview Mar 28, 2026 5:07pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

📝 Walkthrough

Walkthrough

Fixed a stray leading character causing a parse error in frontend/db/index.ts, added a script to generate a .env from .env.example, and updated netlify.toml to run that script during the build and remove the removed plugin entry. (47 words)

Changes

Cohort / File(s) Summary
Syntax Fix
frontend/db/index.ts
Removed stray leading 0 from the STRICT_LOCAL_DB_GUARD constant declaration to fix a parse error (no API changes).
Build Configuration
netlify.toml
Replaced build command to run bash scripts/generate-env.sh before npm ci and npm run build; removed netlify-plugin-bundle-env plugin entry.
Env Generation Script
frontend/scripts/generate-env.sh
Added script that reads uppercase variable names from .env.example, writes present environment values into .env, and overwrites .env on each run.

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

  • AM1007
  • ViktorSvertoka
  • liudmylasovetovs

Poem

🐇 A tiny typo hopped away,

envs now lined up in a row,
build learns to write what it may,
.env wakes — the app can go! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing Netlify SSR deployment by generating a .env file at build time to deliver environment variables to the SSR runtime.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sl/feat/db-optimization

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7750e08 and 50c6789.

📒 Files selected for processing (2)
  • frontend/db/index.ts
  • netlify.toml

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
frontend/scripts/generate-env.sh (2)

1-7: Consider adding set -e for fail-fast behavior.

If .env.example is 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 .env entries.

If an environment variable value contains newlines, unescaped quotes, or other special characters, the resulting .env line could be invalid. Quoting values provides safer output for most .env parsers.

♻️ 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 > .env

Note: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 50c6789 and 2510901.

📒 Files selected for processing (2)
  • frontend/scripts/generate-env.sh
  • netlify.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • netlify.toml

@ViktorSvertoka ViktorSvertoka merged commit 9240c21 into develop Mar 28, 2026
7 checks passed
@ViktorSvertoka ViktorSvertoka deleted the sl/feat/db-optimization branch March 28, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants