Created
April 6, 2017 14:54
-
-
Save tomfun/f821e284fdaad365922b921861ef74bc to your computer and use it in GitHub Desktop.
tested in AWS in Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* | |
If you are using docker, you must change CMD from | |
CMD node www-server.js | |
to | |
CMD ["node", "www-server.js"] | |
*/ | |
require('http-shutdown').extend() | |
var http = require('http'); | |
var server = http.createServer((req, res) => { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
setInterval(function() { | |
res.end(' World\n'); | |
},10000); | |
console.log("Hello"); | |
}) | |
.withShutdown() | |
.listen(4000, '0.0.0.0'); | |
console.log('server started'); | |
process.on('SIGTERM', () => { | |
console.log('on: SIGTERM down the server'); | |
server.shutdown(function() { | |
console.log('Everything is cleanly shutdown.'); | |
process.exit(0); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment