Created
December 5, 2016 10:34
-
-
Save tjconcept/210fd5cb3d14312563dedfce20bb06c3 to your computer and use it in GitHub Desktop.
Minimal HTTP server
This file contains 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
'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