Skip to main content

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
  • 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 /download page

Behavior

  • /api/img only allows whitelisted keys: products/*, cards/*, documents/*.
  • Sensitive request headers are filtered before forwarding (such as host, cookie, and authorization).
  • set-cookie related response headers are removed.
  • Upstream redirect Location headers are rewritten to the /proxy/download prefixed path.
  • Adds X-Proxy-Upstream response header for troubleshooting.

Required Binding

In Cloudflare Pages project settings, configure R2 bucket binding:

  • Variable name: IMG_R2
  • Bind both environments: Production and Preview

If the binding is missing, /api/img returns 500.

Local Debug

bun run build
bunx wrangler pages dev

Default URL: http://localhost:8788