pillarjs / path-to-regexp

Turn a path string such as `/user/:name` into a regular expression

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

throw new TypeError(`Unexpected ${nextType} at ${index}, expected ${type}`)

SoulNaturalist opened this issue · comments

Error
image

My code

import * as Koa from 'koa';
import * as Router from 'koa-router';

const app = new Koa();
const router = new Router();

router.get('/*', async (ctx) => {
    ctx.body = 'Hello World!';
});

app.use(router.routes());

app.listen(3000);

I started my app:

npx ts-node app.ts

And get that error...
How i can solve that?

That’s not a valid route for this library. Please read the README. You can do (.*) instead.

It was in the Koa examples, strange that it can't be done, thanks anyway!

It's from an earlier release that used to allow that instead of (.*). It's something that's been discussed as adding back, but nothing has really been implemented on that front.