Astro + Functions
Hello!
I have an Astro project deployed on Cloudflare pages. I deploy it using GitLab CI which does the Wrangler CLI command. wrangler pages deploy .../dist/ --project-name ... --branch main´
My main goal is to keep the Astro static, and therefore have an API call within a contact page go to Functions.
I keep failing miserably and since I have no insight to what is working in the background cannot debug it properly. I roughly followed this Tutorial
My setup builds the Astro project into the dist/ folder, I then move my functions/ folder with the js scripts in there, followed by the Wrangler command.
Is my mistake there?
In my page I have a script part, which does:
const response = await fetch('/api/submit-form', {
method: 'POST',
...
And the functions folder has a functions/api/submit-form.js
So far all I get is 405 from both the page and a direct postman call. Not sure if this is maybe some cross origin issues or if I even reach this function at all.
Relevant test page: https://staging.personal-website-staging.pages.dev/contact/
Thanks for your help!
1 Reply
After deeper reading I figured this out.
The key misunderstanding from my side was that the output_dir is not the place where functions should be, but rather functions need to be at the $PWD where the wrangler command is run.
Come to think of it, good simple design 😄