Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does vert.x have centralized filtering?

Tags:

vert.x

I am new to Vert.X.

Does Vert.x have a built in facility for centralized filters? What I mean are the kind of filters that you would use on a J2EE application.

For instance, all pages have to go through the auth filter, or something like that.

Is there a standardized way to achieve this in Vert.x?

like image 516
MrSynAckSter Avatar asked Dec 11 '22 00:12

MrSynAckSter


1 Answers

I know this question is quite old, but for those still looking for filter in Vertx 3, the solution is to use subRouter as a filter:

    // Your regular routes
    router.route("/").handler((ctx) -> {
        ctx.response().end("...");
    });
    // Have more routes here...

    Router filterRouter = Router.router(vertx);

    filterRouter.get().handler((ctx)->{
        // Do something smart

        // Forward to your actual router
        ctx.next();
    });
    filterRouter.mountSubRouter("/", router);
like image 59
Alexey Soshin Avatar answered Jan 25 '23 15:01

Alexey Soshin