Created
February 2, 2016 08:40
-
-
Save Codesleuth/727ab26ccb4bfb760d84 to your computer and use it in GitHub Desktop.
A simple HTTP server which prints request information and returns 200
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
var http = require('http'); | |
var server = http.createServer(function (req, res) { | |
var datas = []; | |
req.on('data', function (data) { | |
datas.push(data); | |
}); | |
req.on('end', function () { | |
console.log('>-------------------->'); | |
console.log(new Date); | |
console.log(req.method + " " + req.url); | |
for (var header in req.headers) | |
console.log(header + ": " + req.headers[header]); | |
console.log(); | |
var reqBody = Buffer.concat(datas).toString('utf8'); | |
console.log(reqBody); | |
res.statusCode = 200; | |
res.setHeader('content-type', 'text/xml'); | |
res.end(); | |
}); | |
}); | |
server.listen(1337, function () { | |
console.log('Listening on http://0.0.0.0:1337 ...'); | |
}); |
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
import * as http from 'http' | |
const server = http.createServer((req, res) => { | |
let datas: Buffer[] = [] | |
req.on('data', (data: Buffer) => { | |
datas.push(data) | |
}) | |
req.on('end', () => { | |
console.log('>-------------------->') | |
console.log(new Date) | |
console.log(`${req.method} ${req.url}`) | |
for (var header in req.headers) | |
console.log(`${header}: ${req.headers[header]}`) | |
console.log() | |
const reqBody = Buffer.concat(datas).toString('utf8') | |
console.log(reqBody) | |
res.statusCode = 200 | |
res.setHeader('content-type', 'text/xml') | |
res.end() | |
}) | |
}) | |
server.listen(1337, () => { | |
console.log('Listening on http://0.0.0.0:1337 ...') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment