Skip to content
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

Query parameters in path cause exception #85

Open
dimitrovs opened this issue Jan 25, 2021 · 3 comments
Open

Query parameters in path cause exception #85

dimitrovs opened this issue Jan 25, 2021 · 3 comments

Comments

@dimitrovs
Copy link

I understand query parameters are not supported for routing but even using a path with them throws exception:

import { Router, Method } from 'tiny-request-router'

const router = new Router()
router.post('/v1/relays', handleAddRelay);
router.post('/?action=host', handleInitHost);

Causes:

Uncaught TypeError: Unexpected MODIFIER at 1, expected END\n  at line 21 in h\n  at line 21 in i\n  at line 21 in a\n  at line 21 in s\n  at line 21 in e._push\n  at line 21 in e.post\n  at line 1\n  at line 1 in n\n  at line 1\n  at line 1\n
@steverandy
Copy link

I'm also getting exception when using star wildcard

router.get("/api*", handleApiRoute);
router.get("/", handleStaticRoute);
TypeError: Unexpected MODIFIER at 4, expected END

@metaskippy
Copy link

metaskippy commented Sep 16, 2022

Same issue here. It would be awesome if the query string parameters were stripped from the URL, dumped into the response object, and routing worked as normal.

Even better would be to parse those query string parameters and put the key/value pairs into the response object.

@bribes
Copy link

bribes commented Oct 30, 2022

I understand query parameters are not supported for routing but even using a path with them throws exception:

import { Router, Method } from 'tiny-request-router'

const router = new Router()
router.post('/v1/relays', handleAddRelay);
router.post('/?action=host', handleInitHost);

Causes:

Uncaught TypeError: Unexpected MODIFIER at 1, expected END\n  at line 21 in h\n  at line 21 in i\n  at line 21 in a\n  at line 21 in s\n  at line 21 in e._push\n  at line 21 in e.post\n  at line 1\n  at line 1 in n\n  at line 1\n  at line 1\n

Can't you just put the router as just '/' and then get the parameters of it? router.post('/', handleInitHost);.

In the fetch event listener you would have to define the parameter const { searchParams } = new URL(request.url);, then pass it in event.respondWith(match.handler(match.params, searchParams)), then in the function you can get the parameters by using .get(parameter) on the searchParams.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants