File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
packages/cloudflare/src/cli/templates Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @opennextjs/cloudflare " : patch
3+ ---
4+
5+ Serve ` /cdn-cgi/image/... ` images in dev
Original file line number Diff line number Diff line change @@ -32,6 +32,20 @@ export default {
3232
3333 populateProcessEnv ( url , env . NEXTJS_ENV ) ;
3434
35+ // Serve images in development.
36+ // Note: "/cdn-cgi/image/..." requests do not reach production workers.
37+ if ( url . pathname . startsWith ( "/cdn-cgi/image/" ) ) {
38+ const m = url . pathname . match ( / \/ c d n - c g i \/ i m a g e \/ .+ ?\/ (?< url > .+ ) $ / ) ;
39+ if ( m === null ) {
40+ return new Response ( "Not Found!" , { status : 404 } ) ;
41+ }
42+ const imageUrl = m . groups ! . url ! ;
43+ return imageUrl . match ( / ^ h t t p s ? : \/ \/ / )
44+ ? fetch ( imageUrl , { cf : { cacheEverything : true } } )
45+ : env . ASSETS . fetch ( new URL ( `/${ imageUrl } ` , url ) ) ;
46+ }
47+
48+ // Fallback for the Next default image loader.
3549 if ( url . pathname === "/_next/image" ) {
3650 const imageUrl = url . searchParams . get ( "url" ) ?? "" ;
3751 return imageUrl . startsWith ( "/" )
You can’t perform that action at this time.
0 commit comments