You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@jonathanong my understanding is that you would like that "route" functions signature only receive the context (ctx) and the next one in the list, are called when the previous returns;
Silly example:
functioncall1(ctx){ctx.body=['called-1']}functioncall2(ctx){ctx.body.push('called-2')}functioncall3(ctx){ctx.body.push('called-3')ctx.body=ctx.body.join(':')}constapp=newKoa()app.use(match('/a/b',[call1,call2,call3]))// Response body should be a string with value 'called1:called2:called3'
when I look to that, I see it's neater, however I wouldn't like to miss the possibility to have middlewares only in some routes, for example
constbodyParser=require('koa-bodyparser')constpathMatch=require('koa-path-match')...functionloginPage(ctx){// Render login page}functionverifyLogin(ctx){// do things to validate and responds}constmatch=pathMatch()constparser=bodyParser()constapp=newKoa()app.use(match('/login').get(loginPage).post([parser,verifyLogin])
If we don't pass next to the route functions then bodyParser cannot be used only in the post verb, I would have to add as a middleware before match middleware. Correct?
like regular middleware. might be needed to support #14
still think it's an anti-pattern MOST of the time since your logic should be refactored into functions, not middleware.
The text was updated successfully, but these errors were encountered: