-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
POST handler executed instead of GET handler #6507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This sounds impossible and I can't reproduce it with your example. Could you add some logging to your server's // Add this before your route definitions
app.use((req, res, next) => {
console.log(req.method, req.url, req.headers['user-agent'])
next()
}) BTW please don't send archives (or links to archives) on GitHub - include short snippets of code or use a separate repo/gist. |
Ok, you were right, something I don't get is happening at the client side, so nothing to do with express: here is the listing you asked for, it shows that the server is actually getting a POST request: And here is a video that shows the strange behavior (caused by the client ..or my misunderstanding of what the browser is doing): |
The User Agent is one of a browser. Your video shows that the browser performs a fetch request to URL ending with I'd suggest using |
Thank a lot that was very helpful, I am closing this thread |
I have sent the full code below. To reproduce the strange behavior:
Run both the server and the client, send a request throw the form , check that you are sending a GET request using developer tools then, on the server check that the app.post handler is being executed. Note that there ia a problem in the form, it is not executing the js script because of a missing property in the button (type="button"), so the type of the button is by default "submit" and the request that is being sent is a GET request sending the data on the URL query part. But why is the server executing the app.post handler?
Environment information
Version:
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.5.0",
"express": "^5.1.0",
"mysql2": "^3.14.0",
"sequelize": "^6.37.7"
}
Platform:
Microsoft Windows NT 10.0.26100.0
x64
Node.js version:
v22.14.0
Any other relevant information:
Full code is here:
Description: a server app and a client app, just add a MySQL server connection details or simply remove connection to DB as it is not relevant here:
https://drive.google.com/file/d/1P-50C95h5RAMYarO-scfUHaLLPq1mmZF/view?usp=sharing
The text was updated successfully, but these errors were encountered: