[articleId].ts. A catch all for all domain.com/<id>.domain.com itself. Which I do not want, as it will trigger the function for no reason._routes.json:/functions directory and placing scripts there: https://developers.cloudflare.com/pages/functions/get-started/, however I also noticed that Astro has this guide on endpoints: https://docs.astro.build/en/guides/endpoints/, and it seems this could also work? However, when using Cloudflare Pages for deployment, I am not sure which method is recommended. If i follow Astro's guide on endpoints, would these automatically be served by Pages in a similar way to the Functions? Anyone with experience with deploying Astro to Cloudflare Pages can shine some light on this?
ms. More CPU-heavy things will increase it (hashing passwords). This is not the same as the time a fetch request takes - a request might take 10 seconds but only use 1ms of CPU Time.[articleId].tsdomain.com/<id>domain.com_routes.json/functionsms{
"version": "1",
"include": ["/*"],
"exclude": "/"
}// src/middleware.js
export async function onRequest({ request, locals }, next) {
// Check if the current request path matches the specific form action path
if (new URL(request.url).pathname === '/form-path' && request.method === 'POST') {
try {
// Process form data
const formData = await request.formData();
// Example of form data processing.
if(formData.get('name') !== "john") {
throw new Error("Name must be john!")
}
// After processing successfully, redirect to `/form-submitted`
return Response.redirect(new URL("/form-submitted", request.url), 302);
} catch (error) {
// If there's an error in processing, set `locals.formError`
// This can later be checked in the endpoint handling the form submission
locals.formError = error.message;
}
}
// If the path does not match, proceed with the normal request flow.
return next();
}