mirror of https://gitlab.com/curben/blog
fix(cf-images): switch origin
This commit is contained in:
parent
af1a4614eb
commit
78d5348e41
|
@ -17,6 +17,15 @@ export default {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (/image-resizing/.test(request.headers.get("via"))) {
|
||||||
|
return new Response('Request loop', {
|
||||||
|
status: 403,
|
||||||
|
headers: {
|
||||||
|
'Cache-Control': 'no-cache'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// https://developers.cloudflare.com/images/url-format#supported-formats-and-limitations
|
// https://developers.cloudflare.com/images/url-format#supported-formats-and-limitations
|
||||||
if (!/\.(jpe?g|png|gif|webp)$/i.test(pathname)) {
|
if (!/\.(jpe?g|png|gif|webp)$/i.test(pathname)) {
|
||||||
return new Response('Invalid file extension', {
|
return new Response('Invalid file extension', {
|
||||||
|
@ -72,9 +81,7 @@ export default {
|
||||||
|
|
||||||
// Build a request that passes through request headers
|
// Build a request that passes through request headers
|
||||||
// Images are stored on https://gitlab.com/curben/blog/-/tree/site
|
// Images are stored on https://gitlab.com/curben/blog/-/tree/site
|
||||||
// curben.pages.dev returns 502 error
|
const imageURL = new URL(imgPath, 'https://mdleom.com/')
|
||||||
// curben.gitlab.io returns 403 error
|
|
||||||
const imageURL = new URL(imgPath, 'https://curbengh.github.io/')
|
|
||||||
const imageRequest = new Request(imageURL, {
|
const imageRequest = new Request(imageURL, {
|
||||||
headers: request.headers
|
headers: request.headers
|
||||||
})
|
})
|
||||||
|
@ -90,15 +97,15 @@ export default {
|
||||||
response.headers.set('Vary', 'Accept')
|
response.headers.set('Vary', 'Accept')
|
||||||
return response
|
return response
|
||||||
} else if (response.status === 404) {
|
} else if (response.status === 404) {
|
||||||
const { readable, writable } = new TransformStream()
|
|
||||||
// Custom 404 page
|
// Custom 404 page
|
||||||
|
const { readable, writable } = new TransformStream()
|
||||||
const { status, statusText } = response
|
const { status, statusText } = response
|
||||||
|
|
||||||
const htmlHeader = new Headers({
|
const htmlHeader = new Headers({
|
||||||
...request.headers,
|
...request.headers,
|
||||||
Accept: 'text/html'
|
Accept: 'text/html'
|
||||||
})
|
})
|
||||||
const page404 = new Request('https://curbengh.github.io/404', {
|
const page404 = new Request('https://mdleom.com/404', {
|
||||||
headers: htmlHeader
|
headers: htmlHeader
|
||||||
})
|
})
|
||||||
const res404 = await fetch(page404)
|
const res404 = await fetch(page404)
|
||||||
|
|
Loading…
Reference in New Issue