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
~MARSMAN~
~MARSMAN~•4d ago
Response in postman
No description
~MARSMAN~
~MARSMAN~•4d ago
the body that was sent through postman
No description
~MARSMAN~
~MARSMAN~•4d ago
fetch in js
No description
~MARSMAN~
~MARSMAN~•4d ago
express view
No description
~MARSMAN~
~MARSMAN~•4d ago
what might be the issue?
Hashi
Hashi•4d ago
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.
~MARSMAN~
~MARSMAN~•4d ago
yes, that 404 error only appears in the live website tho
~MARSMAN~
~MARSMAN~•4d ago
No description
~MARSMAN~
~MARSMAN~•4d ago
request headers
No description
caldane
caldane•4d ago
Is your website on a different port than your express server?
~MARSMAN~
~MARSMAN~•4d ago
hmm I'm not sure how I can check that, the host uses CPanel.
caldane
caldane•4d ago
Not sure I have never used cpanel for nodejs, let me do some research
~MARSMAN~
~MARSMAN~•4d ago
yeah I will search too
Hashi
Hashi•4d ago
Can you share also headers, url, payload being send through Postman?
~MARSMAN~
~MARSMAN~•4d ago
No description
~MARSMAN~
~MARSMAN~•4d ago
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
caldane
caldane•4d ago
Well that would likely be a problem unless they have different urls
~MARSMAN~
~MARSMAN~•4d ago
they also said this in regard to my issue, I even tried to create an endpoint like /join and the same issue still appears
No description
Hashi
Hashi•4d ago
Is the postman requesting to the same url as your "fetch()" function does, the "absolute url"?
caldane
caldane•4d ago
Is everything in express or is this a server client architecture?
~MARSMAN~
~MARSMAN~•4d ago
yes postman is requesting the absolute url
~MARSMAN~
~MARSMAN~•4d ago
No description
Hashi
Hashi•4d ago
Oh I think I have an answer, I see HTTP there not HTTPS here Origin is HTTPS
~MARSMAN~
~MARSMAN~•4d ago
yes everything is in express
Hashi
Hashi•4d ago
Switch to https in postman and it will break there too most likely
~MARSMAN~
~MARSMAN~•4d ago
yes it did break 🫠
~MARSMAN~
~MARSMAN~•4d ago
No description
~MARSMAN~
~MARSMAN~•4d ago
the same error
Hashi
Hashi•4d ago
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
~MARSMAN~
~MARSMAN~•4d ago
yeah, at least we found the issue. I will figure out the solution. thank you guys!