Last active
August 8, 2016 20:55
-
-
Save neowulf/b01b786542bf5c54e98bb988c029b84a to your computer and use it in GitHub Desktop.
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'); | |
http.createServer(function(request, response) { | |
var headers = request.headers; | |
var method = request.method; | |
var url = request.url; | |
var body = []; | |
request.on('error', function(err) { | |
console.log(new Date().toString()) | |
console.error(err); | |
}).on('data', function(chunk) { | |
body.push(chunk); | |
}).on('end', function() { | |
console.log(new Date().toString()) | |
body = Buffer.concat(body).toString(); | |
console.log(method + " " + url); | |
console.log("Headers:\n" + JSON.stringify(headers, null, 2)); | |
console.log("Body:\n" + JSON.stringify(JSON.parse(body), null, 2)); | |
//send mock response | |
response.on('error', function(err) { | |
console.error(err); | |
}); | |
response.statusCode = 200; | |
response.setHeader('Content-Type', 'application/json'); | |
var responseBody = { | |
headers: headers, | |
method: method, | |
url: url, | |
body: body | |
}; | |
response.write(JSON.stringify(responseBody)); | |
response.end(); | |
console.log("----\n") | |
}); | |
}).listen(8081); | |
console.log("Listening on 8081") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment