Skip to content

Commit

Permalink
fix ^/ regexp and last /
Browse files Browse the repository at this point in the history
  • Loading branch information
zedgu committed Jun 8, 2015
1 parent 2c6f776 commit 00cc038
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/ovenware.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,18 @@ ovenware.regRoutes = function() {

for (var handler in ctrl) {
var route = ctrl.routes[handler] || conf.routes[handler];

if (route && route.method && ~methods.indexOf(route.method)) {
if (!/\/$/.test(conf.prefix)) {
conf.prefix += '/';
var routePath = conf.prefix;
if (!/\/$/.test(conf.prefix) && ctrl.ctrlName) {
routePath += '/';
}
var routePath = conf.prefix + ctrl.ctrlName + route.path;
routePath += ctrl.ctrlName + route.path;
if (conf._prefix_flags) {
routePath = new RegExp(routePath, conf._prefix_flags);
}

this.route(route.method, name, routePath, ctrl[handler], handler);
this.route(route.method, name, routePath || '/', ctrl[handler], handler);
}
}
}
Expand Down Expand Up @@ -166,7 +168,7 @@ function setting(options) {
break;
case util.isRegExp(prefix):
conf._prefix_flags = (prefix.ignoreCase ? 'i' : '') + (prefix.global ? 'g' : '');
conf.prefix = /^\//.test(prefix.source) ? prefix.source : '/' + prefix.source;
conf.prefix = /^\^?\\?\//.test(prefix.source) ? prefix.source : '/' + prefix.source;
break;
default:
conf.prefix = '';
Expand Down

0 comments on commit 00cc038

Please sign in to comment.