Pages Functions Routing
Route List
-
functions/api/img.ts- Route prefix:
/api/img - Source: R2 bucket binding
IMG_R2 - Allowed methods:
GET/HEAD - Purpose: Serve H Series images by same-origin path and cache at edge
- Route prefix:
-
functions/proxy/download/[[path]].ts- Route prefix:
/proxy/download/* - Upstream:
https://mirror.novastar.wiki - Allowed methods:
GET/HEAD/OPTIONS - Purpose: Provide same-origin forwarding for the
/downloadpage
- Route prefix:
Behavior
/api/imgonly allows whitelisted keys:products/*,cards/*,documents/*.- Sensitive request headers are filtered before forwarding (such as
host,cookie, andauthorization). set-cookierelated response headers are removed.- Upstream redirect
Locationheaders are rewritten to the/proxy/downloadprefixed path. - Adds
X-Proxy-Upstreamresponse header for troubleshooting.
Required Binding
In Cloudflare Pages project settings, configure R2 bucket binding:
- Variable name:
IMG_R2 - Bind both environments:
ProductionandPreview
If the binding is missing, /api/img returns 500.
Local Debug
bun run build
bunx wrangler pages dev
Default URL: http://localhost:8788