Skip to content
Myr

router: speed up standard app.use(fn)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 996d319 · Browse files · 4 files+115 added−30 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+115 added−30 removed

  • other:+115 added−30 removed

4 files+115 added−30 removed

modified:lib/router/index.js+24 added-22 removed
147 unmodified lines
148 return res.set('Allow', body).send(body);149 });150 }151152 // setup basic req values153 req.baseUrl = parentUrl;154 req.originalUrl = req.originalUrl || req.url;155156 next();157158 function next(err) {159 if (err === 'route') {
2 unmodified lines
162163 var layer = stack[idx++];164 var layerPath;165162 if (!layer) {163 return done(err);164 }165166 if (slashAdded) {167 req.url = req.url.substr(1);168 slashAdded = false;169 }170171 req.baseUrl = parentUrl;172 req.url = protohost + removed + req.url.substr(protohost.length);173 req.originalUrl = req.originalUrl || req.url;174 removed = '';171 if (removed.length !== 0) {172 req.baseUrl = parentUrl;173 req.url = protohost + removed + req.url.substr(protohost.length);174 removed = '';175 }176177 if (!layer) {178 return done(err);179 }180181 try {182 var path = parseUrl(req).pathname;178 if (undefined == path) path = '/';183184 if (!layer.match(path)) return next(err);185186 // route object and not middleware
51 unmodified lines
238 if (c && '/' != c && '.' != c) return next(err);239240 // Trim off the part of the url that matches the route241 // middleware (.use stuff) needs to have the path stripped238 removed = layerPath;239 if (removed.length) {242 if (layerPath.length !== 0) {243 debug('trim prefix (%s) from url %s', layerPath, req.url);244 removed = layerPath;245 req.url = protohost + req.url.substr(protohost.length + removed.length);242 }246244 // Ensure leading slash245 if (!fqdn && req.url[0] !== '/') {246 req.url = '/' + req.url;247 slashAdded = true;248 }247 // Ensure leading slash248 if (!fqdn && req.url[0] !== '/') {249 req.url = '/' + req.url;250 slashAdded = true;251 }252250 // Setup base URL (no trailing slash)251 if (removed.length && removed.substr(-1) === '/') {252 req.baseUrl = parentUrl + removed.substring(0, removed.length - 1);253 } else {254 req.baseUrl = parentUrl + removed;253 // Setup base URL (no trailing slash)254 req.baseUrl = parentUrl + (removed[removed.length - 1] === '/'255 ? removed.substring(0, removed.length - 1)256 : removed);257 }258259 debug('%s %s : %s', layer.handle.name || 'anonymous', layerPath, req.originalUrl);260 var arity = layer.handle.length;
261 unmodified lines
modified:lib/router/layer.js+29 added-8 removed
added:lib/router/match.js+61 added
modified:History.md+1 added
8 unmodified lines
9 * support non-string `path` in `app.use(path, fn)`10 - supports array of paths11 - supports `RegExp`12 * router: fix optimization on router exit13 * router: speed up standard `app.use(fn)`14 * deps: debug@1.0.315 - Add support for multiple wildcards in namespaces16 * deps: methods@1.1.017 - add `CONNECT`
1775 unmodified lines