I get a 405 error, but ONLY on the webhost, not the localhost

For Workes & Pages, what is the name of the domain?

its example.com at first and example.com/ when submitted

What is the error number?

The error number is 405

What is the error message?

Method Not Allowed

What is the issue or error you’re encountering

Hello. I have been trying to make a contact form that sends an email. Wheneverr, I run this on the localhost, it works, just fine, but whenever I run it on the webhost, I get a 405 error.

What steps have you taken to resolve the issue?

I have tried looking up the issue elsewhere, but an issue is that I cannot quite find the exact problem where it works conditionally.

It sounds like you’re probably hitting the asset server with Pages, which will return a 405 if you try and POST to get an asset like an HTML file.

Can you share your Pages project so we can test this? I’d double check your routing, folder structure, etc.

I’ll be happy to do that. I do have one question: is there a preferred way that I can send you the info? The only thing I can imagine is github, but I am curious if there is another way that I haven’t been thinking of. Again, I very much appreciate the support.

A minimal reproduction of the issue via GitHub or similar would be ideal, yes.

Here is the webhost.

https://sendgridtesting.uk/

This is the webhost I have tested it on. Is this enough? I hope you can see exactly what I have been seeing.

I am sorry for the lack of a more prompt response. Life has been hectic.

My theory seems correct in that you’re hitting the asset server on a POST request from your form.

Can you please share your code, or ideally a minimal reproduction of this issue via GitHub?

Sure.

Here you go.

This is not an application designed to run on Cloudflare Pages. It appears to be a webserver built with Node.js and express.

To do this kind of dynamic thing with Pages, you need to use Cloudflare Pages Functions:

Or alternatively, host your Node.js app elsewhere on a VPS, and then simply use Cloudflare to proxy it via their standard DNS offerings.

1 Like

Thank you for the help! I really appreciate this advice.
Are the cloudflare pages just for static sites? That would explain all of these issues piling up.
Do you recommend one way over another? If it doesn’t matter, I will happily look into both.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.