Skip to content

refactor: extract all hardcoded URL/domain literals into internal/urls package#12

Merged
mastermanas805 merged 1 commit into
masterfrom
feat/urls-constants-package
May 11, 2026
Merged

refactor: extract all hardcoded URL/domain literals into internal/urls package#12
mastermanas805 merged 1 commit into
masterfrom
feat/urls-constants-package

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

Every domain rename so far has been a multi-file sed sweep that missed corners. The `instant.dev → instanode.dev` rename touched 28 files and still left stragglers we're finding hours later. The "Use named constants, not inline strings" memo finally applies here.

New `internal/urls/urls.go` package centralises:

Category Constants
Public hostnames `PublicAPIBase`, `PublicMarketingBase`, `StartURLPrefix`, `DeploymentWildcard`, `StoragePublicHost`
Cluster-internal proxies `InternalPGProxy`, `InternalRedisProxy`, `InternalMongoProxy`, `InternalNATSProxy`, `InternalMinIO`
Helper `UpgradeStartURL(jwt)` — single `/start?t=` builder, replaces 12 identical `fmt.Sprintf` sites

Call sites refactored

  • 12 `fmt.Sprintf("https://instanode.dev/start?t=%s", jwtToken)` → `urls.UpgradeStartURL(jwtToken)`
  • `proxiedInternalURL` (4 hardcoded proxy hosts) → `urls.Internal*`
  • `upgradeNote` / `limitExceededNote` bare links → `urls.StartURLPrefix`
  • `canonicalAPIBase` (handlers/auth.go) + `defaultCanonicalResourceURL` (middleware/auth.go) — these were the same literal duplicated in two files, now both alias `urls.PublicAPIBase`
  • 15 user-facing error strings → string concat with `urls.StartURLPrefix`

Audit before/after

Literal Before After
`instanode.dev/start` in non-test handler code 28+ 1 (OpenAPI doc example, appropriate to leave)
Proxy FQDN literals in `handlers/internal_url.go` 4 0

Test plan

  • 12 new sub-tests in `internal/urls/urls_test.go` (`TestPublicHostnames…`, `TestInternalProxyHostnames…`, `TestUpgradeStartURL_Composition`)
  • All existing tests still pass (`TestProxiedInternalURL`, `TestUpgradeNote_`, `TestLimitExceededNote_`, `TestWhoami_`, `TestDeployNew_EnvVars`, all `TestOpenAPI_*`)
  • `go build ./...` passes
  • Live: anonymous /db/new returns `upgrade` on `instanode.dev` + `internal_url` via `instant-pg-proxy` FQDN; /whoami returns identity via the `urls.PublicAPIBase` audience

Out of scope (follow-ups noted in commit)

  • Email templates (45 occurrences in one file) — marketing copy, needs different extraction
  • SDK repos (sdk-go, sdk-node, mcp) — cross-repo coordination
  • Worker / provisioner repos — far fewer URL strings; can do their own
  • OpenAPI bearerAuth description inline example

🤖 Generated with Claude Code

…s package

User-facing pain that drove this: every domain rename or proxy hostname
tweak required scraping the codebase with grep + sed. The instant.dev →
instanode.dev rename earlier today touched 28 files and still missed
some (we're still finding stragglers). The "Use named constants, not
inline strings" memo applies — extracting was overdue.

New package internal/urls/urls.go centralises:

  Public hostnames:
    PublicAPIBase        = "https://api.instanode.dev"
    PublicMarketingBase  = "https://instanode.dev"
    StartURLPrefix       = PublicMarketingBase + "/start"
    DeploymentWildcard   = "deployment.instanode.dev"
    StoragePublicHost    = "s3.instanode.dev"

  Cluster-internal proxy FQDNs (for in-cluster workloads — friction PR #2):
    InternalPGProxy      = "instant-pg-proxy.instant.svc.cluster.local:5432"
    InternalRedisProxy   = "instant-redis-proxy.instant.svc.cluster.local:6379"
    InternalMongoProxy   = "instant-mongo-proxy.instant.svc.cluster.local:27017"
    InternalNATSProxy    = "instant-nats-proxy.instant.svc.cluster.local:4222"
    InternalMinIO        = "minio.instant-data.svc.cluster.local:9000"

  Helper:
    UpgradeStartURL(jwt) — canonical builder for /start?t=<jwt>, replaces
                          12 sites that had identical fmt.Sprintf calls.

Call sites refactored:
  - 12 fmt.Sprintf upgrade-URL calls across 6 provisioning handlers
    → urls.UpgradeStartURL(jwtToken)
  - proxiedInternalURL in handlers/internal_url.go → uses 4 urls.Internal*
  - upgradeNote / limitExceededNote bare links → urls.StartURLPrefix
  - canonicalAPIBase (handlers/auth.go) → alias of urls.PublicAPIBase
  - defaultCanonicalResourceURL (middleware/auth.go) → alias of
    urls.PublicAPIBase  (eliminates the long-standing duplication of the
    same string in two different files)
  - 15 user-facing error strings ("Sign up at https://instanode.dev/start")
    → string concat with urls.StartURLPrefix

Audit results:
  Before:  28+ occurrences of "instanode.dev/start" in non-test handler code
  After:   1 occurrence (an inline example URL inside the OpenAPI JSON
           description string — appropriate to leave as a literal since it's
           sample documentation, not a runtime-constructed URL)

  Before:  4 proxy FQDN string literals in handlers/internal_url.go
  After:   0 (all 4 use urls.* constants)

Tests:
  internal/urls/urls_test.go (12 sub-tests):
    TestPublicHostnames_MatchExpectedShape         — guards 5 public hosts
    TestInternalProxyHostnames_CorrectPortsAndService — guards 5 internal
    TestUpgradeStartURL_Composition                — builder semantics

  Existing tests still pass:
    TestProxiedInternalURL          — 7 sub-cases unchanged after refactor
    TestUpgradeNote_DoesNotMentionTrial / TestLimitExceededNote_… — 6 cases
    TestWhoami_*, TestDeployNew_EnvVars_*, all TestOpenAPI_* — pass

Live verification on v2.1.0-urls-package in prod:
  POST /db/new (fresh) → upgrade host = "instanode.dev"
                         internal_url host = "instant-pg-proxy.instant.svc.cluster.local:5432"
                         note starts with "Works for 24h free"
  GET /api/v1/whoami → 200 with team_id + plan_tier + team_name
                       (proves the middleware audience lookup still works
                        via the urls.PublicAPIBase alias)

Out of scope (separate follow-ups):
  - Email templates in internal/email/email.go (45 occurrences) — these
    are marketing copy strings with their own care; need different
    extraction approach (probably a templated config).
  - SDK references (sdk-go, sdk-node, mcp) — each is its own repo;
    consolidating across modules needs a shared common/urls package and
    cross-repo coordination.
  - Worker / provisioner repos — they have far fewer URL string
    instances and can do their own thing.
  - The OpenAPI bearerAuth description's inline example URL — sample
    documentation, not a runtime URL.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mastermanas805 mastermanas805 merged commit a127e82 into master May 11, 2026
@mastermanas805 mastermanas805 deleted the feat/urls-constants-package branch May 11, 2026 10:02
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