Created
November 9, 2016 20:40
-
-
Save ericychoi/a07d3fe8861031b75ed27a348b0a2c3a to your computer and use it in GitHub Desktop.
A simple http sink in node.js
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 jsonResp = { | |
| "type": "free" | |
| }; | |
| var jsonRespPaid = { | |
| "type": "Paid" | |
| } | |
| var port = process.argv[2]; | |
| http.createServer(function(request,response){ | |
| var body = ""; | |
| request.on('data', function(chunk) { body += chunk; }); | |
| request.on('end', function() { | |
| console.log('POST: ' + body + "\n"); | |
| setTimeout(function() { | |
| response.writeHead(200); | |
| if (request.url.match(/180/)) { | |
| response.write(JSON.stringify(jsonRespPaid)) | |
| } else { | |
| response.write(JSON.stringify(jsonResp)); | |
| } | |
| response.end(); | |
| // process.exit(1); | |
| }, 0) | |
| }); | |
| }).listen(port); | |
| console.log("server started at " + port + "\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment