Handling POST request in Express.js
Hello,
So I have this form that sends an email to a waitlist database, both the form sending form "fetch" and the express view that handles the request works perfectly fine in these two situations:
- Through my local development environment
- and through postman, which sends the request to the live website
both works as expected, but when I submit a form through the live website and try to send it, I get a 404 error in the console and a "Cannot Post" error in the network tab.
30 Replies
Response in postman
the body that was sent through postman
fetch in js
express view
what might be the issue?
If I understand correct the problem is the 404 response after submitting the form from the website, then a screenshot from the network tab for the request might be of some help, the headers, url, and payload for example.
yes, that 404 error only appears in the live website tho
request headers
Is your website on a different port than your express server?
hmm I'm not sure how I can check that, the host uses CPanel.
Not sure I have never used cpanel for nodejs, let me do some research
yeah I will search too
Can you share also headers, url, payload being send through Postman?
this is the payload
and the url is the same
I contacted the support and said the website port for node js is 3000
and it's the same for the express server
Well that would likely be a problem unless they have different urls
they also said this in regard to my issue, I even tried to create an endpoint like /join
and the same issue still appears
Is the postman requesting to the same url as your "fetch()" function does, the "absolute url"?
Is everything in express or is this a server client architecture?
yes postman is requesting the absolute url
Oh I think I have an answer, I see HTTP there not HTTPS
here Origin is HTTPS
yes everything is in express
Switch to https in postman and it will break there too most likely
yes it did break ðŸ«
the same error
Well I have no idea how to help you with that, but basically it works with HTTP and you have to make it work with HTTPS
yeah, at least we found the issue.
I will figure out the solution.
thank you guys!