No more confusing business logic. Now you can respond to every HTTP request personally!
Usage:
npm install prompt-sync
node app.js
Each incoming request will block until an actual human manually responds with a body and status code.
'use strict'; | |
const http = require('http'); | |
const prompt = require('prompt-sync')(); | |
const server = http.createServer( ( req, res ) => { | |
let body = ''; | |
req.on( 'data', chunk => body += chunk.toString() ); | |
req.on( 'end', () => { | |
process.stdout.write( `Got request: ${ body || null }\n` ); | |
let msg = prompt('Please enter an HTTP response body: '); | |
let status = prompt('Please enter an HTTP status code: '); | |
res.writeHead( status | 0, { 'Content-Type': 'text/html' } ); | |
res.end( msg ); | |
}); | |
}); | |
server.listen( 8080 ); |
amazzzzzing