I wrote a simple nodejs code to make request to a server and noticed that on web browser the request is made twice but once when I use CURL.
const http = require('http');
// The server should respind to all request with a string "Hello World"
let count = 0;
const server = http.createServer((req, res) => {
res.end(`${ count} Hello World \n`);
})
// Start the server and have it listen on port 3000
server.listen(3000, () => console.log('The server is is listening on port 3000'));
Can you explain why?
CodePudding user response:
My guess is a preflight request to OPTIONS
. You could look at the network tab in the Chrome console to see. You probably only want to respond to the GET
request.