Skip to content

feat: make PORT and BASE_URL configurable via environment variables#140

Open
godtail wants to merge 2 commits intohusamql3:mainfrom
godtail:enhancement/configurable-port
Open

feat: make PORT and BASE_URL configurable via environment variables#140
godtail wants to merge 2 commits intohusamql3:mainfrom
godtail:enhancement/configurable-port

Conversation

@godtail
Copy link
Copy Markdown

@godtail godtail commented Apr 13, 2026

Summary

  • Made PORT configurable via process.env.PORT with a fallback to 3333.
  • Made BASE_URL configurable via process.env.BASE_URL with a fallback to http://localhost:${PORT}.

🤖 Generated with Pochi | Task

Summary by CodeRabbit

  • Configuration
    • Environment variables now control the application port and base URL for flexible deployments.
    • When environment variables are not provided, the app falls back to the previous local defaults to preserve local development behavior.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 13, 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: 56639fe0-6edc-4f1c-818e-c5f36ff4c97c

📥 Commits

Reviewing files that changed from the base of the PR and between 7d00039 and 9ed9968.

📒 Files selected for processing (1)
  • packages/shared/src/constants/defaults.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/shared/src/constants/defaults.ts

📝 Walkthrough

Walkthrough

The defaults configuration in packages/shared/src/constants/defaults.ts now reads PORT from environment variables (parsed base-10) with a fallback to 3333, and constructs BASE_URL dynamically using process.env.BASE_URL if set, otherwise http://localhost:${PORT}.

Changes

Cohort / File(s) Summary
Configuration Defaults
packages/shared/src/constants/defaults.ts
Added module-scope PORT computed from process.env.PORT (base-10 parsed) with fallback 3333. Updated DEFAULTS.PORT to use PORT and DEFAULTS.BASE_URL to `process.env.BASE_URL

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 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 summarizes the main change: making PORT and BASE_URL environment-configurable with fallbacks, which directly matches the changeset modifications.
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 unit tests (beta)
  • Create PR with unit tests

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

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/shared/src/constants/defaults.ts`:
- Line 7: The BASE_URL constant currently uses the nullish coalescing operator
with process.env.BASE_URL so empty or whitespace-only strings bypass the
fallback; update the logic that sets BASE_URL (the expression using
process.env.BASE_URL and PORT) to treat empty/whitespace values as unset by
trimming the env value first and using a logical OR fallback to the
`http://localhost:${PORT}` URL instead of `??`, i.e. call trim() on
process.env.BASE_URL and fall back when the trimmed result is an empty string.
- Line 1: The PORT constant currently uses parseInt(process.env.PORT, 10) which
can produce NaN for invalid inputs; change the initialization to parse and
validate the environment value: trim and parse process.env.PORT as base 10,
check Number.isInteger(parsed) && parsed >= 1 && parsed <= 65535, and only then
assign it to PORT; otherwise fall back to the default 3333. Update the PORT
declaration (symbol: PORT) so the value is a validated TCP port number to avoid
binding failures at runtime.
🪄 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: ed72b798-f443-48e0-b655-565ce724a204

📥 Commits

Reviewing files that changed from the base of the PR and between b190262 and 7d00039.

📒 Files selected for processing (1)
  • packages/shared/src/constants/defaults.ts

@@ -1,8 +1,10 @@
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3333;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

In JavaScript, what does parseInt("abc", 10) return, and what is the recommended way to validate a TCP port from an environment variable?

💡 Result:

parseInt("abc", 10) returns NaN. The recommended way to validate a TCP port from an environment variable in Node.js is: const portEnv = process.env.PORT; const port = parseInt(portEnv, 10); if (isNaN(port) || port < 1 || port > 65535) { // Invalid port, use default or throw error throw new Error(Invalid PORT: ${portEnv}); } This checks that the parsed value is a valid number between 1 and 65535 (valid TCP port range).

Citations:


🏁 Script executed:

cat -n packages/shared/src/constants/defaults.ts | head -20

Repository: husamql3/db-studio

Length of output: 492


Harden PORT parsing to avoid NaN and invalid ports.

process.env.PORT may contain non-numeric values (e.g., "abc"), which parse to NaN via parseInt(). This breaks server binding at runtime. Add validation to ensure the port is a valid TCP port (1–65535), otherwise use the default.

Proposed fix
-const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3333;
+const rawPort = process.env.PORT?.trim();
+const parsedPort = rawPort ? Number(rawPort) : NaN;
+const PORT =
+	Number.isInteger(parsedPort) && parsedPort >= 1 && parsedPort <= 65535
+		? parsedPort
+		: 3333;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/shared/src/constants/defaults.ts` at line 1, The PORT constant
currently uses parseInt(process.env.PORT, 10) which can produce NaN for invalid
inputs; change the initialization to parse and validate the environment value:
trim and parse process.env.PORT as base 10, check Number.isInteger(parsed) &&
parsed >= 1 && parsed <= 65535, and only then assign it to PORT; otherwise fall
back to the default 3333. Update the PORT declaration (symbol: PORT) so the
value is a validated TCP port number to avoid binding failures at runtime.

Comment thread packages/shared/src/constants/defaults.ts Outdated
@godtail godtail requested a review from husamql3 as a code owner April 13, 2026 07:07
@godtail
Copy link
Copy Markdown
Author

godtail commented Apr 13, 2026

#138

@husamql3
Copy link
Copy Markdown
Owner

Thanks a lot @godtail for your contribution ❤️

I'm very sick today, I'll review it as soon as I can

Appreciated

@husamql3
Copy link
Copy Markdown
Owner

Hi @godtail

I've checked your PR. I'm getting Uncaught ReferenceError: process is not defined at defaults.ts:1:14, idk if you tested it or not. But it's not working.

Plus, you have to update packages/core/vite.config.ts since we have the localhost URL hardcoded

when it's updated please re-request me to review it

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