10

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 ?

user3552178
  • 2,719
  • 8
  • 40
  • 67

1 Answers1

25
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
}
Valera
  • 2,665
  • 2
  • 16
  • 33