Like this? ```ts export const onRequestPost: PagesFunction<{ R2: R2Bucket}> = async (ctx) => { a
Like this?
export const onRequestPost: PagesFunction<{ R2: R2Bucket}> = async (ctx) => {
await ctx.env.R2.put("name", ctx.request.body);
return new Response("ok");
};formData object from the Response
l like when running workers in dev to disable this, but there isn't. This led me to discover the --local false flag. However, this doesn't do anything. I can see my binding is still referencing a local miniflare database. npx wrangler pages dev public --local false I see:npm i cf-bindings-proxy. There are no other projects in the npm registry using cf-bindings-proxy.
[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?
{
"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();
}let photo = document.getElementById("image-file").files[0];
let formData = new FormData();
formData.append("photo", photo);
fetch('/upload/image', {method: "POST", body: formData});formDataResponsel--local falsenpx wrangler pages dev public --local falseYour worker has access to the following bindings:
- D1 Databases:
- DB: database-name (database-id)
⎔ Starting local server...