0

I'm following the text of Kubernetes in Action (Manning Books). Around page 28 is an exercise in running Node on Docker. When I use a browser to run the code, I'm getting two responses for each browser request.

I'm running Windows 10 and Docker for Windows with the WSL2 backend.

Here is the code of app.js:

// Sample program for "Kubernetes in Action", page 28
const http = require('http');
const os = require('os');

// Console output doesn't show when the "docker run ... -d ..." option is used.
console.log("Kubia server starting...");

// For some reason the handler is called twice for each localhost:8080
var handler = function(request, response) {
    var dt = new Date();
    var dtString = dt.toISOString();
    console.log("Received request from " + request.connection.remoteAddress + " at " + dtString);
    response.writeHead(200);
    response.end("You've hit " + os.hostname() + " at " + dtString + "\n");
};

var www = http.createServer(handler);
www.listen(8080);

Here is my Dockerfile:

FROM node:12.18.1
ADD app.js /app.js
ENTRYPOINT ["node", "app.js"]

In that directory I build the image:

docker build -t kubia .

And I run the code:

docker run --name kubia-container -p 8080:8080 kubia

From the browser I get:

You've hit 713d0aa4de7a at 2022-09-01T13:28:11.903Z

But my console says:

Kubia server starting...
Received request from ::ffff:172.17.0.1 at 2022-09-01T13:28:11.903Z
Received request from ::ffff:172.17.0.1 at 2022-09-01T13:28:11.929Z

Of course the browser accepts the first response it gets and ignores any following ones. But why is the server running twice for that localhost:8080 request?

EDITED 9:42 AM: When I use CMD and run curl within it, I get one call through my handler per curl request. I get two for a browser call but one for curl. Maybe this is a browser issue?

Jerome M
  • 19
  • 2

1 Answers1

0

By adding console.log('url', request.url) I can see that my browser is calling /favicon.ico as the 2nd request.

enter image description here

It seems to be a regular question/issue Why is Chrome searching for my favicon.ico when I serve up a file from ASP.NET MVC?

Wiicolas
  • 193
  • 8