Skip to content

Commit

Permalink
fix(Router): fix path parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dalisoft committed May 30, 2021
1 parent b0d9da5 commit ed5d056
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"homepage": "https://github.com/nanoexpress/nanoexpress#readme",
"dependencies": {
"cookie": "^0.4.1",
"fast-decode-uri-component": "^1.0.1",
"fast-query-parse": "^1.2.0",
"path-to-regexp": "^6.2.0",
"uWebSockets.js": "https://github.com/uNetworking/uWebSockets.js/archive/v19.2.0.tar.gz"
Expand Down
8 changes: 8 additions & 0 deletions src/find-route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import fastDecodeURI from 'fast-decode-uri-component';
import { pathToRegexp } from 'path-to-regexp';
import { invalid } from './helpers/index.js';

export default class FindRoute {
constructor(options = {}) {
Expand Down Expand Up @@ -26,6 +28,7 @@ export default class FindRoute {
// eslint-disable-next-line class-methods-use-this
parse(route) {
if (typeof route.path === 'string') {
route.path = fastDecodeURI(route.path);
if (route.path === '*' || route.path === '/*') {
route.all = true;
} else if (route.path.indexOf(':') !== -1) {
Expand All @@ -46,6 +49,11 @@ export default class FindRoute {
route.await = route.handler.toString().includes('await');
route.legacy = route.handler.toString().includes('next(');

if (!route.async && !route.legacy) {
invalid(
'nanoexpress: Route or Middleware should be either async or legacy mode (express middleware like)'
);
}
if (!this.async && route.async) {
this.async = true;
}
Expand Down

0 comments on commit ed5d056

Please sign in to comment.