Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildcard handlers not called if start of the path matches with a static path route #23

Open
opl- opened this issue Jun 23, 2020 · 1 comment

Comments

@opl-
Copy link

opl- commented Jun 23, 2020

Current behavior

Registering a middleware with a given path (for example /a) and a wildcard path (*) on the same Router instance will cause the wildcard middleware handler to not be called if the path we navigate to starts with the given path (for example /b will work, but /ab will return a 404 page).

Using a param handler instead of a wildcard middleware (.get('/:param', () => {...})) results in the same behavior.

Expected behavior

The wildcard middleware handler should be called if the path doesn't match.

Reproduction

const {Cottage} = require('cottage');
const Koa = require('koa');

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

router.use('/a', (ctx) => {
	console.log(Date.now(), 'a', ctx.url);
	ctx.body = 'a';
});

// Path is implicitly '*'
// Replacing this with `router.get('/:param', ...)` also results in an error
router.use((ctx) => {
	console.log(Date.now(), 'wildcard', ctx.url);
	ctx.body = 'wildcard';
});

app.use(router.callback());

app.listen(8080);
  • Navigating to /a returns a
  • Navigating to /ab returns Not Found
  • Navigating to /b returns wildcard

Environment

Cottage: v3.1.3 (npm latest)

@opl-
Copy link
Author

opl- commented Aug 15, 2020

@therne Is there any chance of this being fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant