ZijianHe / koa-router

Router middleware for koa.
MIT License
4.85k stars 406 forks source link

koa-router v9 not supporting wildcard anymore? #527

Open damianobarbati opened 4 years ago

damianobarbati commented 4 years ago

I recently upgraded to koa-router v9 and I see wildcard routes are not supported anymore:

router.all(['/', '/*'], ctx => send(ctx, 'index.html', { root: path.resolve('dist'), setHeaders }));

causes =>

/Users/damians/Desktop/webapp/node_modules/path-to-regexp/dist/index.js:113
        throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type);
              ^

TypeError: Unexpected MODIFIER at 1, expected END
    at mustConsume (/Users/damians/Desktop/webapp/node_modules/path-to-regexp/dist/index.js:113:15)
    at parse (/Users/damians/Desktop/webapp/node_modules/path-to-regexp/dist/index.js:172:9)
    at stringToRegexp (/Users/damians/Desktop/webapp/node_modules/path-to-regexp/dist/index.js:329:27)
    at pathToRegexp (/Users/damians/Desktop/webapp/node_modules/path-to-regexp/dist/index.js:403:12)
    at new Layer (/Users/damians/Desktop/webapp/node_modules/koa-router/lib/layer.js:44:17)
    at Router.register (/Users/damians/Desktop/webapp/node_modules/koa-router/lib/router.js:561:17)
    at Router.all (/Users/damians/Desktop/webapp/node_modules/koa-router/lib/router.js:492:8)
    at file:///Users/damians/Desktop/webapp/src/index.js:56:8
    at ModuleJob.run (internal/modules/esm/module_job.js:138:23)
    at async Loader.import (internal/modules/esm/loader.js:178:24)

Versions:

$ node -v
v14.3.0
$ yarn -v
1.22.4
$ cat package.json| grep koa
        "koa": "^2.12.0",
        "koa-basic-auth": "^4.0.0",
        "koa-better-json": "^1.1.0",
        "koa-body": "^4.1.3",
        "koa-compress": "^4.0.1",
        "koa-helmet": "^5.2.0",
        "koa-no-trailing-slash": "^2.1.0",
        "koa-router": "^9.0.1",
        "koa-send": "^5.0.0",

If full repro is needed I can produce it.

damianobarbati commented 4 years ago

I just noticed a mismatch between repos names and npm packages. I guess I should move this issue to https://github.com/koajs/router ?

yueyagou commented 4 years ago

solution

https://github.com/koajs/router/blob/master/history.md

router.get('(.*)', (ctx) => { ctx.body = 'ok' })