Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A simple HTTP host router.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example
node_modules/.bin
.gitattributes
.gitignore
.npmignore
README.md
main.js
package.json

README.md

Node HTTP host router

... does what it's called: It routes HTTP request by their host.

Features

  • Wildcards and Regular Expressions
  • Unmatching operator
  • WebSocket support (HTTPS comming later)
  • Full Express-integration (optional)

Example

var router = require("host-router"),
    express = require("express"),
    http = require("http");

// Raw function to handle request
function req(res, req) {
    res.end("Hello World from a function!");
}

// Express app
var app = express();
app.use("/", function(res, req, next) {
    res.send("This is express!");
});

// HTTP server
var server = http.createServer(function(res, req) {
    res.end("HTTP, ok?");
});

// Do routing
router({

    // Simple usage & function
    "foobar.com": req,

    // Wildcard & express
    ".yolo.nl": app,

    // Regular Expression & HTTP server
    "/some-regexp/": server

},
80, // Port
"localhost", // Host (optional)
function() {
    console.log("Up and running");
});

Routers

foobar.com

Only works for foobar.com.

.yolo.nl

Routes hi.yolo.nl, sub.foo.yolo.nl but not yolo.nl.

/some-regexp/

A normal Regular Expression, e.g. some-regexp.com or baz.some-regexp.hi.nz.

License

Attribution 3.0 Unported (CC BY 3.0)

Attribution

No attribution needed.

Something went wrong with that request. Please try again.