Skip to content

Commit

Permalink
Handle SIGINT exit, add hostname and \n to resp
Browse files Browse the repository at this point in the history
- Ctrl+C on a Docker container sends SIGINT, which is not handled
  properly by default (see nodejs/node#4182). Added a signal handler.
- Adding trailing newline to response for curl-friendliness.
- Added log message indicating server is starting.
- Added hostname to indicate that the container.

Signed-off-by: Ahmet Alp Balkan <[email protected]>
  • Loading branch information
ahmetb committed Mar 29, 2017
1 parent a78af72 commit d365ab2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion hellonode/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@
*/

var http = require('http');
var os = require('os');

process.on('SIGINT', function() {
console.log('shutting down...');
process.exit();
});

var handleRequest = function(request, response) {
console.log('Received request for URL: ' + request.url);
response.writeHead(200);
response.end('Hello, World!');
response.end('Hello, World!\nHostname: ' + os.hostname() + '\n');
};

var www = http.createServer(handleRequest);
console.log('server listening on port 8080');
www.listen(8080);

0 comments on commit d365ab2

Please sign in to comment.