when i use koa-compose with koa-router, koa-router does not work.
See original GitHub issueapp.js
const Koa = require('koa');
const app = new Koa();
const views = require('koa-views')(__dirname + '/views', {
extension: 'pug'
});
const json = require('koa-json');
const onerror = require('koa-onerror');
const bodyparser = require('koa-bodyparser')({
enableTypes:['json', 'form', 'text']
});
const logger = require('koa-logger');
const koa_static = require('koa-static')(__dirname + '/public')
const compose = require('koa-compose');
const index = require('./routes/index');
const users = require('./routes/users');
// error handler
onerror(app);
// composed middleware
const all = compose([
bodyparser,
json,
logger,
koa_static,
views
]);
// routes
app.use(all);
// routes
app.use(index.routes(), index.allowedMethods());
app.use(users.routes(), users.allowedMethods());
module.exports = app;
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
koa router doesn't work, sends 404 - Stack Overflow
1 Answer 1 ... it can help you to solve problem. maybe work. good luck! Share. Share a link to this answer.
Read more >koa-router | koajs
Route paths will be translated to regular expressions used to match requests. Query strings will not be considered when matching requests. 命名路由. Routes...
Read more >koa-router - npm
Express-style routing using app.get , app.put , app.post , etc. Named URL parameters and regexp captures. String or regular expression route ...
Read more >Use Array of Middleware in Koa Router - realguess
But for every router is one handler + formidable or + authed function.. Chao Huang • 7 years ago. Not every route has...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well, looking at this more, you need to instantiate
koa-json
e.g.You’re passing in constructors which are not middleware that Koa understands.
The following minimal works as expected,
Why does…
…not work?