Skip to content

Instantly share code, notes, and snippets.

@hayes
Created March 4, 2015 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayes/b0084ea39052d294a414 to your computer and use it in GitHub Desktop.
Save hayes/b0084ea39052d294a414 to your computer and use it in GitHub Desktop.
www(null, '', 'nrnpm')
unpm.middleware.push(docs)
unpm.server.listen(instance.port)
function docs(respond, matched, unpm, next) {
var headers = respond.req.headers
var route
var acceptable = headers.accept && headers.accept.match(/image|(text\/(?:html|css))/)
var tarball = respond.req.url.match(/\.tgz$/i)
if (acceptable && !tarball) {
route = www.router.match(respond.req.method, respond.req.url)
}
if (!route) return next()
route.fn(respond.req, respond.res, route, www.config)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment