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
can i ask what you like about astro ? i am new to this.
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).
Are you in static mode for Astro?
yes, mostly
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
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