Skip to content

Feat/cloudflare hosting - #1

Merged
vincentbollaert merged 2 commits into
mainfrom
feat/cloudflare-hosting
Jul 31, 2026
Merged

Feat/cloudflare hosting#1
vincentbollaert merged 2 commits into
mainfrom
feat/cloudflare-hosting

Conversation

@vincentbollaert

Copy link
Copy Markdown
Contributor

No description provided.

Environment variables were the one untrusted input without a boundary of
their own, alongside the catalog's schema, persisted-schema and the
revalidated share response.

`configs.ts` read `import.meta.env.VITE_API_URL` directly behind a
`?? "http://localhost:8787"` fallback. Vite inlines env at build time, so
an unset variable was never a startup error — it produced a bundle
quietly pointing at localhost, and every share then failed with
"sharing service unreachable", which reads as an outage rather than a
missing variable.

The schema lives apart from the reader so both runtimes can use it: the
browser parses `import.meta.env`, and `vite.config.ts` parses `loadEnv`
in Node before anything is emitted. A production build missing a variable
now fails, naming it. Dev keeps its localhost default, so `bun dev` still
needs no setup.

`.env.example` is un-ignored because the template is the documentation
for what each variable is.
The SPA gets its own Worker at the apex, the existing API keeps its own
at api.agentsinc.sh. Kept separate rather than merged behind
`run_worker_first` because the API is a public contract the CLI consumes
(`npx agents-inc init <id>`) and should not share a lifecycle with the
UI — a web deploy must not be able to break the CLI's endpoint.

apps/web has no `main`: a Worker serving only static assets needs no
script, and asset requests are then unmetered. `not_found_handling`
is `single-page-application` so a hard refresh on a client-side route
reaches index.html instead of 404ing.

Only the apex is attached. `use-share-link.ts` bakes `location.origin`
into every share link, so a second live hostname would mint links under
whichever one the author happened to be on; www belongs in a redirect
rule, which resolves before the Worker is reached.

The API's production values sit in `env.production` rather than
replacing the top-level ones, because vitest reads wrangler.jsonc via
`configPath` and the CORS cases in index.test.ts assert against the
localhost origin. Named environments inherit nothing, so the bindings
below are deliberate restatements — dropping one removes it at the edge
rather than falling back.

VITE_API_URL is declared in turbo's build `env` so a cached bundle from
another environment cannot be replayed with the wrong API baked in.
CI gates deploy behind typecheck, lint, and both test suites.

Also stops eslint walking `.wrangler/`, which is wrangler dev's bundled
output and was reporting on dependency code every run.
@vincentbollaert
vincentbollaert merged commit 2cae10d into main Jul 31, 2026
1 check passed
@vincentbollaert
vincentbollaert deleted the feat/cloudflare-hosting branch July 31, 2026 22:38
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