I'm struggling to use a page function (for a simple contact form) with Astro

I've been following https://developers.cloudflare.com/pages/functions/plugins/static-forms/, I've put code in functions/contact.js: import staticFormsPlugin from "@cloudflare/pages-plugin-static-forms"; export const onRequest: PagesFunction = staticFormsPlugin({ respondWith: ({ formData, name }) => { const email = formData.get("email"); return new Response( Hello, ${email}! Thank you for submitting the ${name} form., ); }, }); But it fails to recognise and deploy the function with Pages. Nor is there any mention of it in the routes (which are meant to be auto generated?). Not sure what I'm doing wrong, tbh.
6 Replies
ballsnfalls
ballsnfalls2mo ago
can i ask what you like about astro ? i am new to this.
Matt
MattOP2mo ago
sure - I find it very productive. it "just works" for static pages and I like the concept of 'islands' where you can include more interactive content (React et al).
Hello, I’m Allie!
Are you in static mode for Astro?
Matt
MattOP2mo ago
yes, mostly
Hello, I’m Allie!
How can you be mostly? Either you are entirely static, or you aren’t Basically, if any of your pages are SSRed, Astro will override Functions with its own system
gruntlord6
gruntlord62mo ago
You can inject Java script and use widgets, I have an astro site where I use a worker to populate a download counter the javascript handles the data on the client side and a worker provides it

Did you find this page helpful?