| 1 | import { headers } from "next/headers"; |
| 2 | |
| 3 | /** Headers the API sets on file bytes that the browser needs to see unchanged. */ |
| 4 | const FORWARDED = [ |
| 5 | "content-type", |
| 6 | "content-length", |
| 7 | "content-disposition", |
| 8 | "x-content-type-options", |
| 9 | "content-security-policy", |
| 10 | "cache-control", |
| 11 | "etag", |
| 12 | ]; |
| 13 | |
| 14 | /** Streams an API response for file bytes back from this origin. A cross-origin `<img>` or download link would not carry the session cookie, so a private repository's files would 404. */ |
| 15 | export async function proxyApiFile |
| 16 | const upstream = |
| 17 | headers: { cookie: ( |
| 18 | }); |
| 19 | |
| 20 | return new Response |
| 21 | status: upstream.status |
| 22 | headers: FORWARDED.flatMap |
| 23 | const value = |
| 24 | return value ? |
| 25 | }), |
| 26 | }); |
| 27 | } |