diff --git a/_config.yml b/_config.yml index 756c29c..acbdeb0 100644 --- a/_config.yml +++ b/_config.yml @@ -40,6 +40,7 @@ skip_render: include: - "_headers" # Netlify header rule - "_redirects" # Netlify redirects rule + - "_routes.json" # Cloudflare Pages function # Writing new_post_name: :title.md # File name of new posts diff --git a/functions/images/[[catchall]].js b/functions/images/[[catchall]].js new file mode 100644 index 0000000..e13767e --- /dev/null +++ b/functions/images/[[catchall]].js @@ -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) +} diff --git a/source/_routes.json b/source/_routes.json new file mode 100644 index 0000000..0b70362 --- /dev/null +++ b/source/_routes.json @@ -0,0 +1,5 @@ +{ + "version": 1, + "include": ["/images/*"], + "exclude": [] +} diff --git a/wrangler.toml b/wrangler.toml index 6c2da45..49d6e83 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -4,4 +4,10 @@ compatibility_date = "2024-09-23" compatibility_flags = [ "nodejs_compat" ] send_metrics = false +# worker route = { pattern = "https://mdleom.com/images/*", zone_name = "mdleom.com" } + +# pages function +[[services]] +binding = "CF_IMAGES" +service = "cf-images"