mirror of
https://github.com/nestriness/nestri.git
synced 2026-09-19 17:25:19 +03:00
feat(deploy): drop the IaC layer, and make both apps runnable as containers
Moving the issuer's state into Postgres removed the last thing that tied either app to one hosting provider. What was left was a deployment tool describing resources that no longer existed — so this replaces it with `wrangler`, which is what actually deploys a Worker, and adds a second way to run each app that involves no provider at all. Each app now has a `wrangler.jsonc` with an environment per stage, and a `Dockerfile` beside it. The handler is the same one in both cases; what differs is only where its settings come from. Two of them gained a second spelling so that nothing has to branch on the runtime: Postgres arrives as a pooled binding or as `DATABASE_URL`, and the route to the issuer is a service binding or `AUTH_INTERNAL_URL`. That last one is new, and it is a split the binding was already making without saying so. `AUTH_ISSUER_URL` has to be the issuer's public name, because it is compared literally against every token's `iss` claim — but the public name is often not routable from inside a deployment. So the name and the route are two settings now rather than one that cannot be both. DNS moves out of code and into `docs/dns.md`, which lists every hostname and what it is for. Six records that change roughly never did not need a tool, and the table outlives whatever is answering the names — which is the point, since some of them will stop being Workers. The sandbox hostnames are hyphenated rather than nested for the same reason: a certificate covering `*.nestri.io` covers one label and not two, so `api-sandbox.nestri.io` can become an ordinary origin later without a certificate having to be ordered for it first. Also drops `EMAIL_DEV_LOG` from committed configuration into `.dev.vars`, which `wrangler deploy` cannot upload. Printing a live sign-in code to a log should not be one forgotten override away from production.
This commit is contained in:
63
apps/api/wrangler.jsonc
Normal file
63
apps/api/wrangler.jsonc
Normal file
@@ -0,0 +1,63 @@
|
||||
// The public API, deployed as a Cloudflare Worker.
|
||||
//
|
||||
// The same `app/index.ts` also runs as an ordinary HTTP server — see
|
||||
// `app/server.ts` and the `Dockerfile` beside it.
|
||||
//
|
||||
// Hostnames and the reasoning behind their shape: `docs/dns.md`.
|
||||
// Secrets, the Hyperdrive id, and how to deploy: `docs/deploy.md`.
|
||||
{
|
||||
"$schema": "node_modules/wrangler/config-schema.json",
|
||||
"name": "nestri-api",
|
||||
"main": "app/index.ts",
|
||||
"compatibility_date": "2026-09-05",
|
||||
"compatibility_flags": ["nodejs_compat"],
|
||||
"workers_dev": false,
|
||||
"dev": {
|
||||
"port": 3000
|
||||
},
|
||||
|
||||
// `AUTH` routes by binding rather than by hostname, so it is one hop
|
||||
// shorter than a request over the internet and needs no public address.
|
||||
// It is an optimisation and not a requirement: with no such binding the
|
||||
// middleware reaches the issuer over plain HTTP at `AUTH_ISSUER_URL`,
|
||||
// which is what the container path does.
|
||||
//
|
||||
// `wrangler dev` discovers a sibling session serving the same script name,
|
||||
// so running both dev servers wires this up locally.
|
||||
"services": [{ "binding": "AUTH", "service": "nestri-auth" }],
|
||||
"hyperdrive": [
|
||||
{
|
||||
"binding": "HYPERDRIVE",
|
||||
"id": "0000000000000000000000000000dev0",
|
||||
"localConnectionString": "postgres://postgres:postgres@localhost:5432/nestri"
|
||||
}
|
||||
],
|
||||
"vars": {
|
||||
// The issuer's **public** URL, always. A token's `iss` claim carries
|
||||
// the address it was minted through, and verification compares the two
|
||||
// literally — so naming the binding here instead would reject every
|
||||
// real token, and report it as an ordinary 401.
|
||||
"AUTH_ISSUER_URL": "http://localhost:1337"
|
||||
},
|
||||
|
||||
"env": {
|
||||
"sandbox": {
|
||||
"name": "nestri-api-sandbox",
|
||||
"workers_dev": false,
|
||||
"routes": [{ "pattern": "api-sandbox.nestri.io", "custom_domain": true }],
|
||||
"observability": { "enabled": true },
|
||||
"services": [{ "binding": "AUTH", "service": "nestri-auth-sandbox" }],
|
||||
"hyperdrive": [{ "binding": "HYPERDRIVE", "id": "<sandbox-hyperdrive-id>" }],
|
||||
"vars": { "AUTH_ISSUER_URL": "https://auth-sandbox.nestri.io" }
|
||||
},
|
||||
"production": {
|
||||
"name": "nestri-api",
|
||||
"workers_dev": false,
|
||||
"routes": [{ "pattern": "api.nestri.io", "custom_domain": true }],
|
||||
"observability": { "enabled": true },
|
||||
"services": [{ "binding": "AUTH", "service": "nestri-auth" }],
|
||||
"hyperdrive": [{ "binding": "HYPERDRIVE", "id": "<production-hyperdrive-id>" }],
|
||||
"vars": { "AUTH_ISSUER_URL": "https://auth.nestri.io" }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user