Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created August 9, 2012 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save max-mapper/3307779 to your computer and use it in GitHub Desktop.
Save max-mapper/3307779 to your computer and use it in GitHub Desktop.
node simple static router

npm install static (or something)

// static() returns function that takes (req, res)
var handler = static('/static', './static')  <-- serve any static file in the ./static folder
var handler = static('/favicon.ico', './static/favicon.ico') <-- serve ./static/favicon.ico at the /favicon.ico route

var http = require('http');
http.createServer(function (req, res) {
  if (handler(req, res)) return
  else res.end('hello there')
}).listen(1337, '127.0.0.1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment