koa2 - How to redirect some URL conditionally in the koa 2 -
this i'm thinking, pseudo code.
const myredirect = (routepath) => { newurl = routepath; if (matches condition) newurl = do_some_modification(routepath); return next(newurl); } const myfunc = (routepath, myredirect) => (newurl, middleware) => { return (ctx, newurl, next) => { return middleware(ctx, newurl, next); } };
how modify make work please ?
const route = async function(ctx, next){ if(shouldredirect){ ctx.redirect('/redirect-url') // redirect page } else{ ctx.somedata = getsomedata() // ctx.somedata available in next middleware await next() // go next middleware } }
Comments
Post a Comment