Skip to content

build(env): make the backend origin come only from .env - #20

Merged
laithanhhung merged 1 commit into
devfrom
env-required-api-url
Jul 21, 2026
Merged

build(env): make the backend origin come only from .env#20
laithanhhung merged 1 commit into
devfrom
env-required-api-url

Conversation

@laithanhhung

@laithanhhung laithanhhung commented Jul 21, 2026

Copy link
Copy Markdown
Member

The environment files still carried the backend URL as a literal fallback, so the origin lived in two places and a stale literal could quietly win whenever API_BASE_URL was unset. apiBaseUrl now reads the variable and nothing else.

Dropping the fallback would otherwise turn a missing variable into an empty origin — every request resolving against the page URL, failing at runtime with nothing pointing at the cause. So API_BASE_URL is now required: the generator exits non-zero with the fix in the message, before anything is built. The Goong keys stay optional; without them only the map features stop working.

Summary by CodeRabbit

  • Documentation

    • Clarified that API_BASE_URL is required for builds and is exposed to the browser.
    • Documented that Goong keys may remain blank, with only map features affected.
  • Bug Fixes

    • Builds now fail with a clear error when API_BASE_URL is missing.
    • Removed fallback API URLs so the configured environment value is used consistently.

The environment files still carried the backend URL as a literal fallback, so
the origin lived in two places and a stale literal could quietly win whenever
`API_BASE_URL` was unset. `apiBaseUrl` now reads the variable and nothing else.

Dropping the fallback would otherwise turn a missing variable into an empty
origin — every request resolving against the page URL, failing at runtime with
nothing pointing at the cause. So `API_BASE_URL` is now required: the generator
exits non-zero with the fix in the message, before anything is built. The Goong
keys stay optional; without them only the map features stop working.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kody-ai

kody-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Code Review Could Not Complete ⚠️

The review failed before suggestions could be generated.

Reason: The configured API key (google_gemini) is out of credits or has hit its billing limit. Top up the account or adjust the plan.

After fixing the issue, comment @kody review on this PR to re-run the review.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

@laithanhhung
laithanhhung merged commit 4e3212b into dev Jul 21, 2026
0 of 3 checks passed
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b2417d47-86ed-41ab-b2bf-8f15e064883a

📥 Commits

Reviewing files that changed from the base of the PR and between 383eb2d and 724caca.

📒 Files selected for processing (5)
  • .env.example
  • scripts/generate-env.mjs
  • src/environments/environment.development.ts
  • src/environments/environment.production.ts
  • src/environments/environment.ts

📝 Walkthrough

Walkthrough

The build now requires API_BASE_URL during environment generation. Development, production, and shared environment configurations consume env.API_BASE_URL directly, while .env.example documents the requirement and browser exposure.

Changes

API Base URL Configuration

Layer / File(s) Summary
Build-time configuration validation
scripts/generate-env.mjs, .env.example
Environment generation resolves configuration values and exits with code 1 when API_BASE_URL is missing. The example file documents the requirement and browser-bundle behavior.
Fallback removal from environment configurations
src/environments/environment.ts, src/environments/environment.development.ts, src/environments/environment.production.ts
All environment variants assign apiBaseUrl directly from env.API_BASE_URL and document that missing configuration fails the build.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Build
  participant GenerateEnv as scripts/generate-env.mjs
  participant Config as Environment variables and .env
  participant Environment as environment.*.ts
  Build->>GenerateEnv: Run pre* environment generation
  GenerateEnv->>Config: Resolve API_BASE_URL
  alt API_BASE_URL is missing
    GenerateEnv-->>Build: Exit with code 1
  else API_BASE_URL is present
    GenerateEnv-->>Build: Generate env.generated.ts
    Build->>Environment: Read env.API_BASE_URL
  end
Loading

Possibly related PRs

Poem

A bunny checks the URL at dawn,
No hidden fallback lingers on.
The build now stops when keys are bare,
While Goong maps may simply spare.
From .env to browser bright,
Fresh settings hop into the light.

✨ 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 env-required-api-url

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

@coderabbitai coderabbitai Bot mentioned this pull request Jul 24, 2026
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.

1 participant