Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Fixing routing regression (oops!)
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Feb 15, 2016
1 parent 46c5a48 commit f1a802b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ var Router = function () {

return result;
}
}, {
key: "setHost",
value: function setHost(arg) {
if (!array.contains(this.hosts, arg)) {
this.hosts.push(arg);
this.patterns.push(new RegExp("^" + arg.replace(/\*/g, ".*") + "$"));
}

return this;
}
}, {
key: "use",
value: function use(rpath, fn, host, method) {
Expand Down
8 changes: 8 additions & 0 deletions lib/turtleio.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,14 @@ function factory() {
obj.error = errHandler;
}

// Setting default routes
obj.router.setHost("all");

// Registering virtual hosts
Object.keys(obj.config.hosts).forEach(function (i) {
obj.router.setHost(i);
});

return obj;
}

Expand Down
3 changes: 2 additions & 1 deletion sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ server = require(path.join(__dirname, "index"))({
level: "debug"
},
hosts: {
test: "test"
test: "test",
test2: "test2"
}
}, function (req, res, status, body) {
var deferred = defer();
Expand Down
5 changes: 5 additions & 0 deletions sites/test2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>Hello world!!!</h1>
</body>
</html>
9 changes: 9 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ class Router {
return result;
}

setHost (arg) {
if (!array.contains(this.hosts, arg)) {
this.hosts.push(arg);
this.patterns.push(new RegExp("^" + arg.replace(/\*/g, ".*") + "$"));
}

return this;
}

use (rpath, fn, host, method) {
let lpath = rpath,
lfn = fn,
Expand Down
8 changes: 8 additions & 0 deletions src/turtleio.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,14 @@ function factory (cfg = {}, errHandler = null) {
obj.error = errHandler;
}

// Setting default routes
obj.router.setHost("all");

// Registering virtual hosts
Object.keys(obj.config.hosts).forEach(i => {
obj.router.setHost(i);
});

return obj;
}

Expand Down

0 comments on commit f1a802b

Please sign in to comment.