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");
function req(res, req) {
res.end("Hello World from a function!");
}
var app = express();
app.use("/", function(res, req, next) {
res.send("This is express!");
});
var server = http.createServer(function(res, req) {
res.end("HTTP, ok?");
});
router({
"foobar.com": req,
".yolo.nl": app,
"/some-regexp/": server
},
80,
"localhost",
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.sume-regexp.hi.nz
.
License
Attribution 3.0 Unported (CC BY 3.0)
Attribution
Just refer to this repository in some page like imprint, about or contact. Please.