feat: cloudflare pages function

This commit is contained in:
Ming Di Leom 2024-10-06 20:06:16 +00:00
parent 78d5348e41
commit 5fbbd85b12
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
4 changed files with 21 additions and 0 deletions

View File

@ -40,6 +40,7 @@ skip_render:
include: include:
- "_headers" # Netlify header rule - "_headers" # Netlify header rule
- "_redirects" # Netlify redirects rule - "_redirects" # Netlify redirects rule
- "_routes.json" # Cloudflare Pages function
# Writing # Writing
new_post_name: :title.md # File name of new posts new_post_name: :title.md # File name of new posts

View File

@ -0,0 +1,9 @@
export async function onRequestGet(context) {
// const {pathname} = new URL(context.request.url)
// const imageURL = new URL(pathname, 'https://mdleom.com')
// const imageRequest = new Request(imageURL, {
// headers: context.request.headers
// })
// return fetch(imageRequest)
return context.env.CF_IMAGES.fetch(context.request)
}

5
source/_routes.json Normal file
View File

@ -0,0 +1,5 @@
{
"version": 1,
"include": ["/images/*"],
"exclude": []
}

View File

@ -4,4 +4,10 @@ compatibility_date = "2024-09-23"
compatibility_flags = [ "nodejs_compat" ] compatibility_flags = [ "nodejs_compat" ]
send_metrics = false send_metrics = false
# worker
route = { pattern = "https://mdleom.com/images/*", zone_name = "mdleom.com" } route = { pattern = "https://mdleom.com/images/*", zone_name = "mdleom.com" }
# pages function
[[services]]
binding = "CF_IMAGES"
service = "cf-images"