-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Allow parsed url to be passed down #950
Changes from 3 commits
567febe
2ba7995
157fb3f
53fb822
c0f05f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,16 +14,16 @@ export default class Router { | |
this.routes.set(method, routes) | ||
} | ||
|
||
match (req, res) { | ||
match (req, res, url = parse(req.url)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to parse the url here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, removed. |
||
const routes = this.routes.get(req.method) | ||
if (!routes) return | ||
|
||
const { pathname } = parse(req.url) | ||
const { pathname } = url | ||
for (const r of routes) { | ||
const params = r.match(pathname) | ||
if (params) { | ||
return async () => { | ||
return r.fn(req, res, params) | ||
return r.fn(req, res, { ...params, url }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like keeping parsedUrl inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added as fourth argument. |
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to see
url
asparsedUrl
here and everywhere else.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍