Router middleware for Koa. Maintained by @forwardemail and @ladjs.
MIT License
861
stars
178
forks
source link
[fix] When I use multiple routing instances and the request method is incorrect(Define post but use get), the error message is "undefined is not an object (evaluating 'route.methods.length'" #184
Description: When I use multiple routing instances and the request method is incorrect(Define post but use get), the error message is "undefined is not an object (evaluating 'route.methods.length'"
Actual behavior
throw an error
Expected behavior
No-throw error
Code to reproduce
import Koa from 'koa';
import KoaRouter from '@koa/router';
const app = new Koa();
const userRouter = new KoaRouter();
userRouter.prefix('/user');
userRouter.post('/login', (ctx, next) => {
ctx.body = 'login success';
});
const teamRouter = new KoaRouter();
teamRouter.prefix('/team');
teamRouter.post('/test', (ctx, next) => {
ctx.body = 'test success';
});
app.use(userRouter.routes());
app.use(
userRouter.allowedMethods({
throw: true,
notImplemented: () => new Error('notImplemented'),
methodNotAllowed: () => new Error('methodNotAllowed')
})
);
app.use(teamRouter.routes());
app.use(
teamRouter.allowedMethods({
throw: true,
notImplemented: () => new Error('notImplemented'),
methodNotAllowed: () => new Error('methodNotAllowed')
})
);
app.listen(8000, () => {
console.log('success');
});
Checklist
[x] I have searched through GitHub issues for similar issues.
[x] I have completely read through the README and documentation.
[x] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
Describe the bug
Node.js version: 20.11.1
OS version: MacBook Pro macOS 14.1.2
Description: When I use multiple routing instances and the request method is incorrect(Define post but use get), the error message is "undefined is not an object (evaluating 'route.methods.length'"
Actual behavior
throw an error
Expected behavior
No-throw error
Code to reproduce
Checklist