-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add suport for routes with underline and remove default 404 han…
…dler
- Loading branch information
1 parent
2938f85
commit 300d5e3
Showing
3 changed files
with
37 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
const { parse } = require('url') | ||
const UrlPattern = require('url-pattern') | ||
|
||
const patternOpts = { | ||
segmentNameCharset: 'a-zA-Z0-9_-' | ||
} | ||
|
||
const getParamsAndQuery = (pattern, url) => { | ||
const { query, pathname } = parse(url, true) | ||
const route = pattern instanceof UrlPattern ? pattern : new UrlPattern(pattern) | ||
const route = pattern instanceof UrlPattern ? pattern : new UrlPattern(pattern, patternOpts) | ||
const params = route.match(pathname) | ||
|
||
return { query, params } | ||
} | ||
|
||
module.exports = { | ||
getParamsAndQuery | ||
getParamsAndQuery, | ||
patternOpts | ||
} |