Created
July 6, 2015 15:00
-
-
Save Kosta-Github/d66183b6ee8a22475343 to your computer and use it in GitHub Desktop.
echo-service.js
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
var express = require('express'); | |
var http = require('http'); | |
var os = require('os'); | |
var config = { | |
serviceName: 'Echo', | |
hostname: process.env.HOSTNAME || os.hostname(), | |
port: process.env.SERVICE_PORT || 8001 | |
}; | |
var startup_server = function(config) { | |
var app = express(); | |
var server = http.createServer(app); | |
app.use(function(req, res, next) { | |
res.header('X-Bla-Service', config.serviceName); | |
res.header('X-Bla-Version', config.version); | |
res.header('X-Bla-Host', config.hostname); | |
next(); | |
}); | |
app.get('/favicon.ico', function(req, res) { | |
res.send(''); | |
}); | |
app.get('/', function(req, res) { | |
var result = { | |
headers: req.headers, | |
method: req.method, | |
url: req.url, | |
remoteAddress: req.socket.remoteAddress, | |
remotePort: req.socket.remotePort, | |
localAddress: req.socket.localAddress, | |
localPort: req.socket.localPort | |
}; | |
res.status(200).json(result); | |
}); | |
server.listen(config.port); | |
console.log({ config: config }, 'server up and running'); | |
}; | |
startup_server(config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment