Created
June 12, 2020 19:05
-
-
Save athiththan11/54af57401ebae218925d7c366c3282d1 to your computer and use it in GitHub Desktop.
Mock HTTP Socket NodeJS
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
{ | |
"name": "socket-http", | |
"version": "1.0.0", | |
"description": "a simple http socket server", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "athiththan11", | |
"license": "ISC" | |
} |
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
@hostname = localhost | |
@access-token = 1234567890 | |
### Sample Request | |
curl -k GET http://localhost:3000 |
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(onReq).listen(3000); | |
function onReq(req, res) { | |
var socket = res.socket; | |
socket.write( | |
[ | |
'HTTP/1.1 200 OK', // '{"Message":"No DATA"}HTTP/1.1 200 OK' | |
'Content-Type: application/json; charset=UTF-8', | |
'Content-Encoding: UTF-8', | |
'Accept-Ranges: bytes', | |
'Connection: keep-alive', | |
].join('\n') + '\n\n' | |
); | |
socket.write('{"hello": "world"}'); | |
socket.end(); | |
} | |
console.log('Mock server started on port 3000 !!!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment