Created
August 28, 2018 20:47
-
-
Save danielmcq/e2d45f92aa4f0fe0954d674988008180 to your computer and use it in GitHub Desktop.
Fake HTTP server for debugging
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'; | |
const http = require('http'); | |
const port = process.env.PORT||9090; | |
const requestHandler = (request, response) => { | |
let body = Buffer.from('', 'utf8'); | |
request.on('data', data => { | |
body = Buffer.concat([body, data]); | |
}); | |
request.on('end', () => { | |
request.body = body; | |
console.log('url', request.url); | |
console.log('headers', request.headers); | |
console.log('body', request.body.toString()); | |
response.end(request.body.toString()); | |
}); | |
}; | |
const server = http.createServer(requestHandler); | |
server.listen(port, err => { | |
if (err) { | |
return console.log('something bad happened', err); | |
} | |
console.log(`server is listening on ${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment