File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 11const version = "0.0.3"
22
3- const allowedDomains = process ?. env ?. ALLOWED_REMOTE_DOMAINS ?. split ( "," ) || [ "*" ] ;
3+ let allowedDomains = process ?. env ?. ALLOWED_REMOTE_DOMAINS ?. split ( "," ) || [ "*" ] ;
44let imgproxyUrl = process ?. env ?. IMGPROXY_URL || "http://imgproxy:8080" ;
55if ( process . env . NODE_ENV === "development" ) {
66 imgproxyUrl = "http://localhost:8888"
77}
8+ allowedDomains = allowedDomains . map ( d => d . trim ( ) ) ;
89
910Bun . serve ( {
1011 port : 3000 ,
@@ -30,7 +31,13 @@ async function resize(url) {
3031 const preset = "pr:sharp"
3132 const src = url . pathname . split ( "/" ) . slice ( 2 ) . join ( "/" ) ;
3233 const origin = new URL ( src ) . hostname ;
33- if ( ! allowedDomains . includes ( "*" ) && ! allowedDomains . includes ( origin ) ) {
34+ const allowed = allowedDomains . filter ( domain => {
35+ if ( domain === "*" ) return true ;
36+ if ( domain === origin ) return true ;
37+ if ( domain . startsWith ( "*." ) && origin . endsWith ( domain . split ( "*." ) . pop ( ) ) ) return true ;
38+ return false ;
39+ } )
40+ if ( allowed . length === 0 ) {
3441 return new Response ( `Domain (${ origin } ) not allowed. More details here: https://github.com/coollabsio/next-image-transformation` , { status : 403 } ) ;
3542 }
3643 const width = url . searchParams . get ( "width" ) || 0 ;
You can’t perform that action at this time.
0 commit comments