Skip to content

Instantly share code, notes, and snippets.

@roxsross
Created September 6, 2023 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roxsross/333ea7fd6ac94aa1b16aca7d3d85e5e4 to your computer and use it in GitHub Desktop.
Save roxsross/333ea7fd6ac94aa1b16aca7d3d85e5e4 to your computer and use it in GitHub Desktop.
servidor web en Nodejs.
'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