-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The ctx. _matchedRoute is not the match route. #34
Comments
Can you submit a PR that has a failing test case? This is a good find, thank you! |
This is not a bug, it's a feature (kind of). Here is var mostSpecificLayer = matchedLayers[matchedLayers.length - 1]
ctx._matchedRoute = mostSpecificLayer.path;
if (mostSpecificLayer.name) {
ctx._matchedRouteName = mostSpecificLayer.name;
} @BainDragneel in your case matchedLayers look like: [ I can think of better solution. Express allows to specifiy regexp restriction for route param like |
@kroleg This is a bug, see https://github.com/ZijianHe/koa-router/labels/first%20matched%20route Allegedly it was fixed on the original repo for "8.x branch": ZijianHe/koa-router#231 (comment)
but then it must have been lost somewhere along the transition to this repo, as the works on I am currently on And there was also that PR on the original repo which stalled and got closed ZijianHe/koa-router#345 (possibly before the v8.x rewrite). Maybe that could be based on to fix this bug. I am not asking to continue working on the 8.x branch, but only to acknowledge this issue (as reported here and in multiple issues on the original repo) as a real bug and unintended behaviour. That might hopefully encourage someone with enough time at hand to pick it up and file a PR. |
If anyone makes a PR I will award them a bug bounty, payable over PayPal. |
@niftylettuce I've found this PR on the original repo which possibly fixes this issue: ZijianHe/koa-router#525 and also something somewhat related: ZijianHe/koa-router#492 |
Can someone review @mdenisov PR #93? cc @falkenhawk @mdenisov if you're confident about it lmk |
@niftylettuce I transferred this PR from the original repo and this fix solves this problem. Works great on my project :) |
@mdenisov can you please send me your PayPal or preferred means of receiving a donation for your bug bounty award here? niftylettuce@gmail.com |
@niftylettuce It is not necessary, thanks :) |
|
Thanks very much, I have some things I did not pay attention to this issue in time, sorry! |
node.js version: v13.0.1
npm/yarn and version: 6.12.0
koa-router
version: 7.4.0 and i tried @koa/router v8.0.2, too.koa
version: 2.7.0Code sample:
Now I have two routes, one is "/api/order/list" and another is "/api/order/:orderId" ,
I want to log each request.I want the url I am recording to be the url of my own defined api, not the url directly with params.For example, when I request "http://127.0.0.1:3000/api/order/57d52c52403f2ee865738ec7", I want to record that the url is "/api/order/:orderId" instead of "/api/order/57d52c52403f2ee865738ec7",And when I request "http://127.0.0.1:3000/api/order/list", I want to record that the url is "/api/order/list" instead of "/api/order/:orderId".
But ctx. _matchedRoute is not the route I requested.
Expected Behavior:
when I request "http://127.0.0.1:3000/api/order/list", ctx. _matchedRoute is "/api/order/:orderId"
Actual Behavior:
ctx. _matchedRoute is "/api/order/list"
Additional steps, HTTP request details, or to reproduce the behavior or a test case:
i have the four screenshots.
http:127.0.0.1:3000/api/order/list
ctx.matched
http:127.0.0.1:3000/api/order/:orderId
ctx.matched
The text was updated successfully, but these errors were encountered: