Feat/cloudflare hosting - #1
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.