-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add support for query parameters #5
Conversation
I like the idea, but if I recall correctly the url.parse method was deprecated in Node 11.0.0. I'll take your PR as a starting point, write a test against this case and implement this change with the newer WHATWG URL API. Thanks! |
Great, should I do this or will you? |
Feel free to take a crack at it if you'd like, I've already tried with the new URL API and it seems that the request doesn't get passed the full URL for some reason which makes the URL parsing fail in the new API. I'm still working on it, but it will probably be a few days until I can push anything into the repo. |
Hey, Sorry for the late reply... I did some research and stumbled upon nodejs/node#12682. Based on that, here are the possible solutions I found:
I'd personally suggest method 2. It seems to be the most well-supported option. |
I think option 1 is fine. The comment below it says that you'll be in trouble when there is a backslash in path, but I think this case is rare. Are they even legal in HTTP request? Since the “micro” framework is dealing with HTTP anyway, we can have dummy prefix like http://example.com/. |
Yes, that seems fine. I've implemented that solution and it seems to be working fine. @nahtnam I'll push this change into a separate branch, would you mind pulling it and making sure that it works? I'll be adding full support for query parameters by simply passing the new WHATWG URL .searchParams object right onto the request object as .searchParams. I've written a new test to ensure this functionality works, but I'd like a second pair of eyes if possible before pushing it into NPM 😉 |
@protocol114 Looks good to me! Few nitpicky things but would it be better if we use Thanks! |
Did you get a chance to review the changes/publish? |
Another comment is with this line of code: https://github.com/protocol114/micro-http-router/blob/queryParams/src/router.js#L160 Just FYI that is a https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams object so you cant just do |
@nahtnam That serialization will eat repeated keys like |
@FranklinYu Good catch. For some reason I thought |
Sorry to keep bugging you guys, but any update? This is blocking some of my other work. I tried to publish my initial PR under Thanks! |
Sorry friend, been super busy with life things. I've got a quick change to make to my branch and I'll push it up and publish to npm sometime today. |
OK, sorry again. Just pushed up a new update 1.4.0 into npm that has the query param changes and a new Let me know if everything's working correctly. |
No worries, thank you for all of the efforts you put. I do need either a I am working on a framework which lets you hotswap routes so you don't have to wait for the server to restart every time you make a change (which can take a couple of seconds for big apps). But my issue is if someone changes a route from |
I had some free time and added both an |
Works perfectly, thank you! |
Currently, if you have a URL such as
/?hello=world
, the router says that the route is not found. I made changes so that it ignores all query params and matches only the route itself (/
).