Skip to content

feat(dev): prompt for a base URL in setup-env, defaulting to unset - #5385

Open
IamCoder18 wants to merge 1 commit into
Kilo-Org:mainfrom
IamCoder18:feat/setup-env-prompt-base-url
Open

feat(dev): prompt for a base URL in setup-env, defaulting to unset#5385
IamCoder18 wants to merge 1 commit into
Kilo-Org:mainfrom
IamCoder18:feat/setup-env-prompt-base-url

Conversation

@IamCoder18

Copy link
Copy Markdown
Contributor

Summary

pnpm dev:setup-env now prompts for a BASE_URL ("the URL you use to access the dev server") at the start, before the NEXTAUTH_URL prompt. When provided, it becomes the default for NEXTAUTH_URL (which the user can still override) and APP_URL_OVERRIDE is also written so auth and server-side redirects resolve at the same public origin — useful for LAN testing (http://192.168.1.82:3100) and dev URLs behind Cloudflare Access (https://clouddev.example.com). Pressing enter leaves both unset, so NEXTAUTH_URL falls back to the http://localhost:3000 example default. CI mode (--ci) skips the BASE_URL prompt and preserves the existing CI placeholders.

Both prompts share a URL validator with a non-fatal recovery menu (no fatal exit):

  • Rejects whitespace/quotes/newlines/# (env-reserved), unparseable input, non-http/https protocol, missing hostname.
  • Suggests a fix when the input is missing a protocol (e.g. 192.168.1.82:3100http://192.168.1.82:3100).
  • On invalid input: prints the error, offers [r] Re-enter / [s] Use suggested (when available) / [d] Use default or clear. Enter defaults to d.

APP_URL_OVERRIDE is appended to .env.local since it isn't in .env.local.example; the file-write path already handles that.

Verification

  • pnpm exec oxlint dev/local/setup-env.ts — 0 warnings, 0 errors.
  • pnpm exec tsc --noEmit --target es2022 --module nodenext --moduleResolution nodenext --strict --skipLibCheck dev/local/setup-env.ts — clean.
  • Manual smoke test of the validateUrl helper via node -e against 10 inputs covering valid LAN/Cloudflare-Access/localhost URLs, protocol-less host:port (suggests http:// prefix), wrong protocol (ftp:), garbage strings, whitespace, and #-fragment inputs. All produce the expected ok/error/suggestion result.
  • No automated tests exist for dev/local/setup-env.ts in the repo, so the prompt flow itself was not exercised end-to-end.
  • Pre-push hook (pnpm format:check, pnpm lint, pnpm typecheck --changes-only) ran clean on push.

Visual Changes

N/A

Reviewer Notes

  • validateUrl returns the user's exact input (not parsed.origin) on success, so what you type is what gets written to .env.local. The runtime already derives .origin when it reads APP_URL_OVERRIDE / NEXTAUTH_URL via new URL(...).origin, so a trailing path is harmless — but I chose not to silently rewrite the value. Happy to normalize to origin (reject paths/queries) if you'd rather enforce the strict origin form.
  • The "use default / clear" recovery option always returns ''. The caller maps '' to the appropriate fallback: empty for BASE_URL (unset), the shown default for NEXTAUTH_URL (base URL or http://localhost:3000). So one recovery path serves both prompts.
  • The validator's "suggest http://" path only fires when the input contains no ://. It does not try to fix typos like htttp:// or missing single slashes — those surface as a parse error with a re-enter prompt.

Add a BASE_URL prompt at the start of pnpm dev:setup-env, before the
NEXTAUTH_URL prompt. The prompt asks for 'the URL you use to access
the dev server' (e.g. http://192.168.1.82:3100 for LAN testing,
https://clouddev.example.com behind Cloudflare Access). When
provided, it becomes the default for the NEXTAUTH_URL prompt — the
user can still override it — and APP_URL_OVERRIDE is also written so
auth and server-side redirects resolve at the same public origin.
Pressing enter at the BASE_URL prompt leaves both unset, so the
NEXTAUTH_URL prompt falls back to the http://localhost:3000 example
default. CI mode skips the BASE_URL prompt and preserves the
existing CI placeholders. APP_URL_OVERRIDE is appended to
.env.local since it is not present in .env.local.example; the
file-write path already handles that.

Both prompts validate the URL: no whitespace/quotes/newlines/'#'
(env-reserved), parseable, http or https protocol, non-empty
hostname. On invalid input the user gets a non-fatal recovery menu
with options to re-enter, accept a suggested fix (e.g. prepend
http:// for a protocol-less host:port), or fall back to the
default / clear — no fatal errors.
@kilo-code-bot

kilo-code-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • dev/local/setup-env.ts

Reviewed by grok-4.6 · Input: 120.8K · Output: 21.3K · Cached: 246K

Review guidance: REVIEW.md from base branch main

@IamCoder18

Copy link
Copy Markdown
Contributor Author

Ready for review!

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