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: Same-origin forwarding kept for existing /proxy/download/* links. The /download page embeds https://mirror.novastar.wiki/ directly, because the mirror loads its CSS, JS and files from root-relative paths that do not resolve under this prefix.

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