@@ -109,6 +109,143 @@ describe('Providers', () => {
109109 }
110110 } )
111111
112+ it ( 'cloudflare with app.baseURL' , ( ) => {
113+ const ctx = { options : { ...emptyContext . options , nuxt : { baseURL : '/admin/' } } } as any
114+
115+ expect ( cloudflare ( ) . getImage ( '/images/test.png' , {
116+ modifiers : { width : 200 } ,
117+ baseURL : '/' ,
118+ } , ctx ) ) . toMatchObject ( { url : '/cdn-cgi/image/w=200/admin/images/test.png' } )
119+
120+ expect ( cloudflare ( ) . getImage ( '/images/test.png' , {
121+ modifiers : { } ,
122+ baseURL : '/' ,
123+ } , ctx ) ) . toMatchObject ( { url : '/admin/images/test.png' } )
124+ } )
125+
126+ it ( 'cloudflare with external image' , ( ) => {
127+ expect ( cloudflare ( ) . getImage ( 'https://example.com/photo.jpg' , {
128+ modifiers : { width : 200 } ,
129+ baseURL : '/' ,
130+ } , emptyContext ) ) . toMatchObject ( { url : '/cdn-cgi/image/w=200/https://example.com/photo.jpg' } )
131+
132+ expect ( cloudflare ( ) . getImage ( 'https://example.com/photo.jpg' , {
133+ modifiers : { } ,
134+ baseURL : '/' ,
135+ } , emptyContext ) ) . toMatchObject ( { url : 'https://example.com/photo.jpg' } )
136+ } )
137+
138+ it ( 'cloudflare cross-zone' , ( ) => {
139+ const ctx = {
140+ options : {
141+ ...emptyContext . options ,
142+ nuxt : { baseURL : '/' } ,
143+ event : {
144+ headers : new Headers ( {
145+ 'host' : 'app.example.com' ,
146+ 'x-forwarded-proto' : 'https' ,
147+ } ) ,
148+ } ,
149+ } ,
150+ } as any
151+
152+ expect ( cloudflare ( ) . getImage ( '/images/test.png' , {
153+ modifiers : { width : 200 } ,
154+ baseURL : 'https://cdn.example.com' ,
155+ } , ctx ) ) . toMatchObject ( { url : 'https://cdn.example.com/cdn-cgi/image/w=200/https://app.example.com/images/test.png' } )
156+
157+ expect ( cloudflare ( ) . getImage ( '/images/test.png' , {
158+ modifiers : { } ,
159+ baseURL : 'https://cdn.example.com' ,
160+ } , ctx ) ) . toMatchObject ( { url : '/images/test.png' } )
161+ } )
162+
163+ it ( 'cloudflare cross-zone with app.baseURL' , ( ) => {
164+ const ctx = {
165+ options : {
166+ ...emptyContext . options ,
167+ nuxt : { baseURL : '/admin/' } ,
168+ event : {
169+ headers : new Headers ( {
170+ 'host' : 'app.example.com' ,
171+ 'x-forwarded-proto' : 'https' ,
172+ } ) ,
173+ } ,
174+ } ,
175+ } as any
176+
177+ expect ( cloudflare ( ) . getImage ( '/images/test.png' , {
178+ modifiers : { width : 200 } ,
179+ baseURL : 'https://cdn.example.com' ,
180+ } , ctx ) ) . toMatchObject ( { url : 'https://cdn.example.com/cdn-cgi/image/w=200/https://app.example.com/admin/images/test.png' } )
181+
182+ expect ( cloudflare ( ) . getImage ( '/images/test.png' , {
183+ modifiers : { } ,
184+ baseURL : 'https://cdn.example.com' ,
185+ } , ctx ) ) . toMatchObject ( { url : '/admin/images/test.png' } )
186+ } )
187+
188+ it ( 'cloudflare cross-zone with external src' , ( ) => {
189+ const ctx = {
190+ options : {
191+ ...emptyContext . options ,
192+ nuxt : { baseURL : '/' } ,
193+ event : {
194+ headers : new Headers ( {
195+ 'host' : 'app.example.com' ,
196+ 'x-forwarded-proto' : 'https' ,
197+ } ) ,
198+ } ,
199+ } ,
200+ } as any
201+
202+ expect ( cloudflare ( ) . getImage ( 'https://other.example.com/images/test.png' , {
203+ modifiers : { width : 200 } ,
204+ baseURL : 'https://cdn.example.com' ,
205+ } , ctx ) ) . toMatchObject ( { url : 'https://cdn.example.com/cdn-cgi/image/w=200/https://other.example.com/images/test.png' } )
206+
207+ expect ( cloudflare ( ) . getImage ( 'https://other.example.com/images/test.png' , {
208+ modifiers : { } ,
209+ baseURL : 'https://cdn.example.com' ,
210+ } , ctx ) ) . toMatchObject ( { url : 'https://other.example.com/images/test.png' } )
211+ } )
212+
213+ it ( 'cloudflare cross-zone with appOrigin' , ( ) => {
214+ const ctx = {
215+ options : {
216+ ...emptyContext . options ,
217+ nuxt : { baseURL : '/admin/' } ,
218+ } ,
219+ } as any
220+
221+ expect ( cloudflare ( ) . getImage ( '/images/test.png' , {
222+ modifiers : { width : 200 } ,
223+ baseURL : 'https://cdn.example.com' ,
224+ appOrigin : 'https://app.example.com' ,
225+ } , ctx ) ) . toMatchObject ( { url : 'https://cdn.example.com/cdn-cgi/image/w=200/https://app.example.com/admin/images/test.png' } )
226+ } )
227+
228+ it ( 'cloudflare cross-zone appOrigin overrides headers' , ( ) => {
229+ const ctx = {
230+ options : {
231+ ...emptyContext . options ,
232+ nuxt : { baseURL : '/' } ,
233+ event : {
234+ headers : new Headers ( {
235+ 'host' : 'injected.attacker.com' ,
236+ 'x-forwarded-proto' : 'https' ,
237+ } ) ,
238+ } ,
239+ } ,
240+ } as any
241+
242+ expect ( cloudflare ( ) . getImage ( '/images/test.png' , {
243+ modifiers : { width : 200 } ,
244+ baseURL : 'https://cdn.example.com' ,
245+ appOrigin : 'https://app.example.com' ,
246+ } , ctx ) ) . toMatchObject ( { url : 'https://cdn.example.com/cdn-cgi/image/w=200/https://app.example.com/images/test.png' } )
247+ } )
248+
112249 it ( 'cloudinary' , ( ) => {
113250 const providerOptions = {
114251 baseURL : '/' ,
0 commit comments