fix(stats): route /data with a query string to the stats worker (#62193)

This commit is contained in:
Dax
2026-11-05 16:45:19 -05:00
committed by GitHub
Unverified
parent 2f9cbcf4eb
commit 386229c1ab
2 changed files with 8 additions and 14 deletions
+7 -13
View File
@@ -80,22 +80,16 @@ const app = new sst.cloudflare.x.SolidStart("Stats", {
})
// The site serves itself under /data and /<locale>/data, and these routes are its only way in: it has no custom domain
// or workers.dev URL. Route patterns can't wildcard the middle of a path, hence one pair per locale. `sst dev` deploys
// no Worker.
// or workers.dev URL. An exact `/data` pattern misses `/data?query`, so each pattern is a `/data*` prefix. Route patterns
// can't wildcard the middle of a path, hence one per locale. `sst dev` deploys no Worker.
const appServer = app.nodes.server
if (appServer) {
for (const prefix of ["data", ...LOCALES.map((locale) => `${locale}/data`)]) {
const name = prefix.replaceAll("/", "")
for (const [suffix, pattern] of [
["", `${domain}/${prefix}`],
["Path", `${domain}/${prefix}/*`],
]) {
new cloudflare.WorkersRoute(`StatsRoute${name}${suffix}`, {
zoneId: zoneID,
pattern,
script: appServer.nodes.worker.scriptName,
})
}
new cloudflare.WorkersRoute(`StatsRoute${prefix.replaceAll("/", "")}`, {
zoneId: zoneID,
pattern: `${domain}/${prefix}*`,
script: appServer.nodes.worker.scriptName,
})
}
}
+1 -1
View File
@@ -42,4 +42,4 @@ To run one sync pass on your machine against a stage's resources, run `bun sst s
Stats HTML, JSON, and Markdown use a one-minute browser cache and a five-minute shared cache. Expired responses must revalidate instead of serving stale snapshots.
The Worker has no custom domain. `infra/stats.ts` routes `/data`, `/data/*`, `/<locale>/data` and `/<locale>/data/*` on the main host straight to it, so its responses skip the Cloudflare cache and reach browsers with these headers unchanged. Static assets are uploaded under `/data`, and the build moves Nitro's `_headers` to the assets root so they stay immutable.
The Worker has no custom domain. `infra/stats.ts` routes `/data*` and `/<locale>/data*` on the main host straight to it, so its responses skip the Cloudflare cache and reach browsers with these headers unchanged. Static assets are uploaded under `/data`, and the build moves Nitro's `_headers` to the assets root so they stay immutable.