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