I'm using koa-router to define routing paths
var app = require('koa')();
var router = require('koa-router')();
app.use(router.get('/apples', function *(next) {
}));
app.use(router.get('/oranges', function *(next) {
}));
app.use(router.routes());
app.listen(8080);
How do I define a route to handle everything that hasn't got a defined route? i.e. in this case, all other paths apart from /apples and /oranges.
You could add a catch-all after the routes. Unmatched requests should fall through to it.
router.get('/oranges', function *(next) {...});
router.get('/apples', function *(next) {...});
app.use(router.routes());
app.use(function*(next) {
// handle unmatched...
});
...hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With