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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With