Skip to content

Instantly share code, notes, and snippets.

@kevincennis
Created May 26, 2016 23:59
Show Gist options
  • Save kevincennis/a1145ae0915e1baa6c8c8a7c5031b537 to your computer and use it in GitHub Desktop.
Save kevincennis/a1145ae0915e1baa6c8c8a7c5031b537 to your computer and use it in GitHub Desktop.
Proctored Node Server

Proctored Web Server

No more confusing business logic. Now you can respond to every HTTP request personally!

Usage:

  1. npm install prompt-sync
  2. 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 );
@samccone
Copy link

amazzzzzing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment