snnsnn
snnsnn
CDCloudflare Developers
Created by snnsnn on 8/19/2024 in #pages-help
Do middlewares are counted as functions?
Hi everyone, I am new to cloudflare and trying to learn pages. On the pages websites, it is said "On both free and paid plans, requests to static assets are free and unlimited. A request is considered static when it does not invoke Functions." https://developers.cloudflare.com/pages/functions/pricing/#static-asset-requests I was wondering if invoking a middleware is counted as invoking a function. To be more specific, I am using functions/_middleware.js to serve static assets and I am not sure if such a middleware incur cost for serving a static file.
export async function onRequest(ctx) {
const { pathname } = new URL(ctx.request.url);

if (pathname.startsWith('/static')) {
return await ctx.env.ASSETS.fetch(ctx.request.url);
}

return new Response(HTML, {
headers: { 'Content-Type': 'text/html' },
});
}
export async function onRequest(ctx) {
const { pathname } = new URL(ctx.request.url);

if (pathname.startsWith('/static')) {
return await ctx.env.ASSETS.fetch(ctx.request.url);
}

return new Response(HTML, {
headers: { 'Content-Type': 'text/html' },
});
}
If so, is there a way to serve those static files without a middleware?
9 replies