1 import { getCloudflareContext } from "@opennextjs/cloudflare"
2
3 /**
4 * Fetches a static asset through the worker's ASSETS binding and returns the
5 * raw response so callers can stream the body instead of buffering it. Returns
6 * null outside Cloudflare (next dev / build) or when the asset doesn't exist.
7 */
8 export async function fetchAssetResponse(
9 url: string
10 ): Promise<Response | null> {
11 try {
12 const { env } = await getCloudflareContext({ async: true })
13 const res = await env.ASSETS?.fetch(url)
14 return res?.ok ? res : null
15 } catch {
16 return null
17 }
18 }