Skip to content

Commit

Permalink
fix(router): parse url using URL for pathname (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 15, 2022
1 parent 4229ce0 commit a1f975f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,10 @@ export function createRouter (opts: CreateRouterOptions = {}): Router {

// Main handle
router.handler = eventHandler((event) => {
// Match route

// Remove query parameters for matching
let path = event.req.url || '/'
const queryUrlIndex = path.lastIndexOf('?')
if (queryUrlIndex > -1) {
path = path.substring(0, queryUrlIndex)
}
const path = new URL(event.req.url || '/', 'http://localhost').pathname

// Match route
const matched = _router.lookup(path)
if (!matched) {
if (opts.preemtive) {
Expand Down
2 changes: 1 addition & 1 deletion test/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('router', () => {
})

it('Handle url with query parameters, include "?" in url path', async () => {
const res = await request.get('/test/?/a?title=test')
const res = await request.get('/test/?/a?title=test&returnTo=/path?foo=bar')
expect(res.status).toEqual(200)
})

Expand Down

0 comments on commit a1f975f

Please sign in to comment.