Skip to content

(SP: 1) [FIX] Hot fix index APP ENV#421

Merged
ViktorSvertoka merged 2 commits intodevelopfrom
lso/feat/fix-env
Mar 28, 2026
Merged

(SP: 1) [FIX] Hot fix index APP ENV#421
ViktorSvertoka merged 2 commits intodevelopfrom
lso/feat/fix-env

Conversation

@liudmylasovetovs
Copy link
Copy Markdown
Collaborator

@liudmylasovetovs liudmylasovetovs commented Mar 28, 2026

Description

Fixes a runtime crash in Netlify caused by frontend/db/index.ts defaulting APP_ENV to 'local' when the environment variable is missing or unreadable at function runtime.

This change makes local database mode opt-in only, trims env values before use, and prevents deploy/runtime environments from silently falling back to local PostgreSQL logic.


Related Issue

Issue: #<issue_number>


Changes

  • removed the implicit APP_ENV ?? 'local' fallback in frontend/db/index.ts
  • introduced explicit IS_LOCAL_ENV detection so local DB mode is enabled only when APP_ENV === 'local'
  • trimmed and validated DATABASE_URL / DATABASE_URL_LOCAL before initializing Drizzle
  • improved error messages for undefined or invalid APP_ENV values in runtime

Database Changes (if applicable)

  • Schema migration required
  • Seed data updated
  • Breaking changes to existing queries
  • Transaction-safe migration
  • Migration tested locally on Neon

How Has This Been Tested?

  • Tested locally
  • Verified in development environment
  • Checked responsive layout (if UI-related)
  • Tested accessibility (keyboard / screen reader)

Screenshots (if applicable)

Not applicable — backend/runtime env fix only.


Checklist

Before submitting

  • Code has been self-reviewed
  • No TypeScript or console errors
  • Code follows project conventions
  • Scope is limited to this feature/fix
  • No unrelated refactors included
  • English used in code, commits, and docs
  • New dependencies discussed with team
  • Database migration tested locally (if applicable)
  • GitHub Projects card moved to In Review

Reviewers

Summary by CodeRabbit

  • Bug Fixes
    • Normalized environment detection by trimming and lowercasing APP_ENV so local vs non-local is determined reliably.
    • Tightened DATABASE_URL presence checks by trimming values to ignore surrounding whitespace.
    • Improved error messages for missing or misconfigured environment variables to report when APP_ENV is undefined.

@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 7:22am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c21d5da5-a3be-416b-bf97-dfa1c995dd8d

📥 Commits

Reviewing files that changed from the base of the PR and between 0425173 and 3f1906e.

📒 Files selected for processing (1)
  • frontend/db/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/db/index.ts

📝 Walkthrough

Walkthrough

Normalized and trimmed environment variables in database config: APP_ENV is trimmed and lowercased (may be undefined), IS_LOCAL_ENV boolean added for flow decisions, and DATABASE_URL / DATABASE_URL_LOCAL are trimmed. Error messages now surface APP_ENV ?? 'undefined' when appropriate.

Changes

Cohort / File(s) Summary
Database Configuration
frontend/db/index.ts
Trim and lowercase APP_ENV; introduce IS_LOCAL_ENV boolean; trim DATABASE_URL and DATABASE_URL_LOCAL; update guards to use IS_LOCAL_ENV; adjust error messages to include APP_ENV ?? 'undefined' and tighter presence checks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰
I nibble vars with careful care,
Trimming edges, making fair.
Local or not, I check the sign—
IS_LOCAL_ENV helps me align.
Undefined no more is hid; I share the line.

🚥 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 reflects the main change: fixing a runtime crash by addressing APP_ENV handling in frontend/db/index.ts, which is the core of the changeset.
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 lso/feat/fix-env

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.

🧹 Nitpick comments (2)
frontend/db/index.ts (2)

14-15: Consider case-insensitive comparison for APP_ENV.

The comparison APP_ENV === 'local' is case-sensitive. If APP_ENV is set to 'LOCAL' or 'Local', IS_LOCAL_ENV will be false, causing the production branch to be used unexpectedly.

Other files in the codebase use .toLowerCase() for this check:

  • frontend/lib/tests/helpers/db-safety.ts uses (process.env.APP_ENV ?? 'local').toLowerCase()
  • frontend/tests/e2e/shop-checkout-local.spec.ts uses .trim().toLowerCase()
♻️ Suggested fix for case-insensitive comparison
-const APP_ENV = process.env.APP_ENV?.trim();
-const IS_LOCAL_ENV = APP_ENV === 'local';
+const APP_ENV = process.env.APP_ENV?.trim().toLowerCase();
+const IS_LOCAL_ENV = APP_ENV === 'local';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/db/index.ts` around lines 14 - 15, The equality check for APP_ENV in
frontend/db/index.ts is case-sensitive (const IS_LOCAL_ENV = APP_ENV ===
'local'), so values like 'LOCAL' or 'Local' fail; update the logic to normalize
APP_ENV (e.g., call .trim().toLowerCase() or (APP_ENV ??
'').trim().toLowerCase()) before comparing and set IS_LOCAL_ENV based on the
lowercased value to ensure a case-insensitive check while preserving the APP_ENV
variable name.

14-15: db-safety.ts has different APP_ENV fallback behavior than the new code.

The test helper frontend/lib/tests/helpers/db-safety.ts (line 6) defaults unset APP_ENV to 'local', whereas the code here treats it as undefined. This differs from most other test helpers (shop-checkout-local.spec.ts, setup.ts) which default to empty string instead.

If intentional (test helpers more permissive), consider adding a comment to clarify. Otherwise, align db-safety.ts to match the stricter behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/db/index.ts` around lines 14 - 15, The test helper db-safety.ts
currently defaults APP_ENV to 'local' which diverges from the new behaviour used
by APP_ENV and IS_LOCAL_ENV in frontend/db/index.ts; update db-safety.ts to
match by reading APP_ENV with the same semantics (e.g. use
process.env.APP_ENV?.trim() and compute IS_LOCAL_ENV as APP_ENV === 'local') so
unset APP_ENV is treated as undefined/empty string, or alternatively add a clear
comment in db-safety.ts explaining the intentional permissive default if you
want to keep it.
🤖 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 14-15: The equality check for APP_ENV in frontend/db/index.ts is
case-sensitive (const IS_LOCAL_ENV = APP_ENV === 'local'), so values like
'LOCAL' or 'Local' fail; update the logic to normalize APP_ENV (e.g., call
.trim().toLowerCase() or (APP_ENV ?? '').trim().toLowerCase()) before comparing
and set IS_LOCAL_ENV based on the lowercased value to ensure a case-insensitive
check while preserving the APP_ENV variable name.
- Around line 14-15: The test helper db-safety.ts currently defaults APP_ENV to
'local' which diverges from the new behaviour used by APP_ENV and IS_LOCAL_ENV
in frontend/db/index.ts; update db-safety.ts to match by reading APP_ENV with
the same semantics (e.g. use process.env.APP_ENV?.trim() and compute
IS_LOCAL_ENV as APP_ENV === 'local') so unset APP_ENV is treated as
undefined/empty string, or alternatively add a clear comment in db-safety.ts
explaining the intentional permissive default if you want to keep it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ef58e934-7db5-4927-a6a1-e2a3b73d6cce

📥 Commits

Reviewing files that changed from the base of the PR and between 87694c3 and 0425173.

📒 Files selected for processing (1)
  • frontend/db/index.ts

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