This is what 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 to modify it to make it work please ?
const route = async function(ctx, next){
if(shouldRedirect){
ctx.redirect('/redirect-url'); // redirect to another page
return;
}
ctx.someData = getSomeData(); // ctx.someData will be available in the next middleware
await next(); // go to next middleware
}