Skip to content

Open source alternative to Semrush and Ahrefs

Run hosted prod next to its database in us-east-1 instead of Smart Placement (#838)

Ben Senescu80010616e344
diff --git a/deploy/alchemy/alchemy.run.ts b/deploy/alchemy/alchemy.run.ts
index 5df2b339..819c23b8 100644
--- a/deploy/alchemy/alchemy.run.ts
+++ b/deploy/alchemy/alchemy.run.ts
@@ -39,7 +39,8 @@ import {
// The worker's runtime contract — compatibility date/flags, crons,
// observability, placement, DO/workflow classes — has one source of truth:
// wrangler.jsonc (what local dev and Docker self-host already run). Only
-// stage-dependent values (names, domains, env) live in this file.
+// stage-dependent values (names, domains, env, and prod's placement override)
+// live in this file.
// unstable_readConfig ships types too loose to lint; validate what we consume.
const wrangler = z
.object({
@@ -453,8 +454,15 @@ export default Alchemy.Stack(
enabled: wrangler.observability?.enabled ?? true,
traces: { enabled: wrangler.observability?.traces?.enabled ?? false },
},
- placement:
- wrangler.placement?.mode === "smart" ? { mode: "smart" } : undefined,
+ // Hosted prod pins the fetch handler next to its Postgres primary
+ // (PlanetScale, AWS us-east-1); each request makes several sequential
+ // Hyperdrive round trips. Other stages run on D1 and keep
+ // wrangler.jsonc's Smart Placement.
+ placement: prod
+ ? { mode: "targeted", region: "aws:us-east-1" }
+ : wrangler.placement?.mode === "smart"
+ ? { mode: "smart" }
+ : undefined,
// Scheduled rank checks — src/server.ts `scheduled` handler.
crons: wrangler.triggers.crons,
env: {
diff --git a/wrangler.jsonc b/wrangler.jsonc
index d8b31596..f7f03398 100644
--- a/wrangler.jsonc
+++ b/wrangler.jsonc
@@ -12,9 +12,11 @@
"enabled": true,
},
},
- // Smart Placement relocates only the `fetch` handler (cron + Workflow runs
- // stay at the edge) toward external subrequests — Postgres via Hyperdrive,
- // SEO APIs — not D1/KV/R2 bindings, so it's a DB no-op on the D1 default.
+ // Smart Placement moves only the `fetch` handler (cron, Workflow, and RPC
+ // runs are unaffected); local dev and Docker ignore it. Hosted prod
+ // overrides it with a us-east-1 region pin next to its Postgres
+ // (deploy/alchemy/alchemy.run.ts), which the legacy `pnpm run deploy` would
+ // undo: it targets the same prod script.
// Must live here: a dashboard-only toggle is wiped by `wrangler deploy`.
"placement": {
"mode": "smart",