Skip to content

Commit 13fc4aa

Browse files
committed
don't pick wildcard when other routes found #36
1 parent bcbbb6f commit 13fc4aa

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.16.5
2+
### Bug fix
3+
* don't pick wildcard when other routes found [#36](https://github.com/jcubic/wayne/issues/36)
4+
15
## 0.16.4
26
### Bug fix
37
* fix check if request origin match

index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,21 @@ export class Wayne {
488488
const routes = this._routes[method];
489489
if (routes) {
490490
const match = this._parser.pick(routes, path, origin);
491+
const have_wildcard = match.length > 1 && match.find(route => {
492+
return !!route.pattern.match(/\*/);
493+
});
491494
if (match.length) {
492-
const [first_match] = match;
493-
const fns = [...this._middlewares, ...routes[first_match.pattern]];
494-
req.params = first_match.data;
495+
let selected_route;
496+
if (have_wildcard) {
497+
selected_route = match.find(route => {
498+
return !route.pattern.match(/\*/);
499+
});
500+
}
501+
if (!(have_wildcard && selected_route)) {
502+
selected_route = match[0];
503+
}
504+
const fns = [...this._middlewares, ...routes[selected_route.pattern]];
505+
req.params = selected_route.data;
495506
setTimeout(function() {
496507
reject('Timeout Error');
497508
}, this._timeout);
@@ -504,7 +515,6 @@ export class Wayne {
504515
if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') {
505516
return;
506517
}
507-
//request = credentials: 'include'
508518
fetch(event.request).then(resolve).catch(reject);
509519
} catch(error) {
510520
this._handle_error(resolve, req, error);

0 commit comments

Comments
 (0)