-
-
Save roxsross/333ea7fd6ac94aa1b16aca7d3d85e5e4 to your computer and use it in GitHub Desktop.
servidor web en Nodejs.
This file contains 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' | |
const greeting = "Hi there, Docker Init onfire" | |
const port = (typeof process.env.PORT !== 'undefined') | |
? process.env.PORT | |
: '80' | |
const express = require('express') | |
const bodyParser = require('body-parser') | |
const app = express() | |
app.use(bodyParser.json()) | |
app.use(bodyParser.urlencoded({extended: true})) | |
// Constants | |
const host = '0.0.0.0'; | |
function format(o, pretty) { | |
return (pretty) | |
? JSON.stringify(o, null, 2) + '\n' | |
: JSON.stringify(o); | |
} | |
app.get('/hello/:name', (req, res) => { | |
var name = req.params.name | |
let timestamp = Date.now() | |
res.send(greeting + " " + name + "<br>\n<i>" + timestamp + "</i>\n") | |
}) | |
app.get('/ping', (req, res) => { | |
res.send("ok") | |
}) | |
const server = app.listen(port, host); | |
console.log(`Service running on http://${host}:${port}`) | |
process.on('SIGTERM', () => { | |
console.info('SIGTERM signal received.'); | |
console.log('Closing http server.'); | |
server.close(() => { | |
console.log('Http server closed.'); | |
process.exit(0); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment