Skip to content

Add local deployment detection and .env file instructions - #20

Merged
surajair merged 1 commit into
mainfrom
claude/setup-route-env-messaging-bk60sk
Jul 29, 2026
Merged

Add local deployment detection and .env file instructions#20
surajair merged 1 commit into
mainfrom
claude/setup-route-env-messaging-bk60sk

Conversation

@surajair

Copy link
Copy Markdown
Contributor

Summary

This PR extends the setup wizard to detect and support local deployments (development servers and self-hosted instances), providing appropriate instructions for configuring environment variables via .env files instead of platform dashboards.

Key Changes

  • Host Detection Enhancement: Added 'local' as a new host type alongside 'vercel', 'netlify', and 'unknown'

    • Detects development builds (NODE_ENV !== 'production') as local
    • Detects production builds served over loopback addresses (localhost, 127.0.0.1, ::1, etc.) as local
    • Accepts optional requestHost parameter to distinguish self-hosted servers from loopback deployments
    • Implements hostnameOf() helper to parse hostnames from request headers, handling IPv6 literals correctly
  • Success Screen Customization: Updated SuccessScreen to provide context-appropriate instructions

    • Shows .env file instructions for local deployments instead of dashboard/redeploy steps
    • Adjusts messaging for database configuration and media storage based on deployment type
    • Clarifies that DATABASE_URL handling differs between hosted and local environments
  • Setup Wizard Improvements: Customized wizard flow for local development

    • Adjusts opening promise ("restart" vs "redeploy") based on host type
    • Provides local-friendly database URL examples (file:./payload.db)
    • Clarifies that database tokens are only needed for hosted databases
    • Updates CLI command messaging to reflect local context
  • Configuration Page Updates: Enhanced post-setup page for local deployments

    • Removes sensitive site IDs from display (page is publicly accessible)
    • Provides appropriate cleanup instructions for local vs hosted environments
    • Adjusts messaging for optional extras configuration
  • SEO & Security: Improved robots.txt and metadata handling

    • Added /setup to robots disallow list (page accepts credentials and reports configuration)
    • Enhanced setup layout metadata with nocache and explicit Googlebot directives
    • Added explanatory comments about why setup route needs multiple noindex signals
  • Test Coverage: Comprehensive test suite for host detection

    • Tests for development/production mode handling
    • Tests for loopback address detection (IPv4, IPv6, localhost variants)
    • Tests for platform variable precedence over loopback detection
    • Tests for edge cases (localhost.example.com should not be treated as local)
    • Tests for hostEnvUrl() returning null for local deployments

Implementation Details

The detectHost() function now accepts an optional requestHost parameter (typically from the HTTP Host header) to distinguish between:

  • Development servers (always local)
  • Production builds on loopback addresses (local self-hosted)
  • Production builds on real domains (platform or unknown)

The loopback detection uses a hostname set for exact matches and suffix matching for .localhost domains, properly handling IPv6 bracket notation and port parsing.

https://claude.ai/code/session_01YK3DzqnUsubgdN3NLgp8D5

The wizard runs just as well against a checkout on someone's own machine as
against a deployment, but every word on the last screen assumed a dashboard
and a redeploy — advice a local user cannot follow.

`detectHost` now recognises `local`: a dev server always, and a production
build reached over loopback, which is `next start` or the compose stack. The
`Host` header is the only thing separating that from a self-hosted server on a
real domain, so the page passes it in. Locally the closing instructions become
the `.env` file and a restart, the database step offers a file URL, and the
token field stops insisting one is required.

The status page is a different problem: once setup has run, anyone who can
reach the site can read it. It no longer prints the site id, and the app check
no longer names the id it expected — it says what is wrong without handing over
a value. In its place is what the reader actually wants to know at that point:
this route has done its job and can be deleted.

/setup is also disallowed in robots.txt now. The page already sent `noindex`,
but a crawler that never fetches it never sees that.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YK3DzqnUsubgdN3NLgp8D5
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
chaibuilder-starter Ready Ready Preview, Comment Jul 29, 2026 7:51am
chaibuilder-starter-bu78 Ready Ready Preview, Comment Jul 29, 2026 7:51am
chaibuilder-starter-mgd7 Ready Ready Preview, Comment Jul 29, 2026 7:51am

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the setup wizard to correctly recognize “local” deployments (dev server or production build served via loopback) and tailor the setup completion instructions accordingly, while also strengthening crawl-prevention for the setup route.

Changes:

  • Extend host detection to include a new local host type, using NODE_ENV and loopback hostname parsing from the request Host header.
  • Update setup wizard + success screen copy to instruct local users to update .env and restart (instead of editing a dashboard and redeploying), including local-friendly DB examples.
  • Add /setup to robots disallow rules and enhance setup-route metadata robots directives; expand integration tests accordingly.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/int/setup-host.int.spec.ts Adds comprehensive host-detection coverage, including local cases and NODE_ENV control.
tests/int/robots.int.spec.ts Verifies /setup is disallowed in robots rules.
src/app/robots.ts Disallows /setup and clarifies rationale in comments.
src/app/(setup)/setup/wizard.tsx Adjusts wizard messaging for local vs hosted environments (restart vs redeploy; DB hints).
src/app/(setup)/setup/SuccessScreen.tsx Provides .env + restart instructions for local deployments and adapts related messaging.
src/app/(setup)/setup/page.tsx Passes request Host header into detection; updates post-setup guidance and removes displayed IDs.
src/app/(setup)/lib/status.ts Avoids printing IDs in misconfiguration messages on a publicly reachable page.
src/app/(setup)/lib/host.ts Implements local detection, loopback hostname parsing, and documents behavior.
src/app/(setup)/layout.tsx Strengthens robots metadata (nocache, explicit Googlebot directives) for setup route.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@surajair
surajair merged commit e7a2f3a into main Jul 29, 2026
5 checks passed
@surajair
surajair deleted the claude/setup-route-env-messaging-bk60sk branch July 29, 2026 07:57
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.

3 participants