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+ if ( url . pathname . startsWith ( "/cdn-cgi/image/" ) ) {
37+ const m = url . pathname . match ( / \/ c d n - c g i \/ i m a g e \/ .+ ?\/ (?< url > .+ ) $ / ) ;
38+ if ( m === null ) {
39+ return new Response ( "Not Found!" , { status : 404 } ) ;
40+ }
41+ const imageUrl = m . groups ! . url ! ;
42+ if ( imageUrl . startsWith ( "http://" ) || imageUrl . startsWith ( "https://" ) ) {
43+ return fetch ( imageUrl , { cf : { cacheEverything : true } } ) ;
44+ }
45+ return 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