Skip to content

Instantly share code, notes, and snippets.

@tjconcept
Created December 5, 2016 10:34
Show Gist options
  • Save tjconcept/210fd5cb3d14312563dedfce20bb06c3 to your computer and use it in GitHub Desktop.
Save tjconcept/210fd5cb3d14312563dedfce20bb06c3 to your computer and use it in GitHub Desktop.
Minimal HTTP server
'use strict';
const http = require('http');
const Promise = require('bluebird');
const tell = require('http-tell');
const infer = require('http-infer');
const dispatch = require('http-dispatch');
const a404 = { code: 404 };
function run( request, response ){
const match = router.match(routes, request.url, request.method);
if (!match)
return tell(response, a404);
const answer = Promise
.join(match, request)
.spread(dispatch)
.then(infer);
return Promise
.join(response, answer)
.spread(tell);
}
http.createServer(run).listen(9000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment