11// The Worker's bindings, in the shape SST's Resource had: `Resource.App.stage` and
2- // `Resource.NAME.value`. STAGE is a text binding in services/www/ cloudflare.config.ts; the other
3- // names are Worker secrets set on the www Worker. Reading a name that isn't bound throws, as SST's
4- // Resource did, so callers keep their fallbacks. package.json `imports` picks this file for builds.
2+ // `Resource.NAME.value`. STAGE is a text binding in cloudflare.config.ts; the other names are
3+ // Worker secrets set on the site Worker. Reading a name that isn't bound throws, as SST's Resource
4+ // did, so callers keep their fallbacks. package.json `imports` picks this file for builds.
55import { env } from "cloudflare:workers"
6- import type { Resources } from "./resource.node"
6+ import type { AssetsBinding , Resources } from "./resource.node"
77
88export { waitUntil } from "cloudflare:workers"
99
@@ -13,7 +13,16 @@ export const Resource = new Proxy({} as Resources, {
1313 get ( _target , name : string ) {
1414 if ( name === "App" ) return { stage : bindings . STAGE === "production" ? "production" : "dev" }
1515 const value = bindings [ name ]
16- if ( typeof value !== "string" || ! value ) throw new Error ( `"${ name } " is not bound to the www Worker` )
16+ if ( typeof value !== "string" || ! value ) throw new Error ( `"${ name } " is not bound to the site Worker` )
1717 return { value }
1818 } ,
1919} )
20+
21+ /**
22+ * The Worker's static assets. Code that needs a built file reads it here: a fetch to the site's
23+ * own URL would not reach this Worker again (Cloudflare sends a Worker's subrequests to its own
24+ * routes past it).
25+ */
26+ export function assets ( ) {
27+ return bindings . ASSETS as AssetsBinding
28+ }
0 commit comments