vert.x 有集中过滤吗? [英] Does vert.x have centralized filtering?

查看:66
本文介绍了vert.x 有集中过滤吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Vert.X 的新手.

I am new to Vert.X.

Vert.x 是否具有用于集中过滤器的内置工具?我的意思是您将在 J2EE 应用程序上使用的那种过滤器.

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.

例如,所有页面都必须通过 auth 过滤器,或者类似的东西.

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

在 Vert.x 中是否有标准化的方法来实现这一点?

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

推荐答案

我知道这个问题已经很老了,但是对于那些还在 Vertx 3 中寻找过滤器的人来说,解决方案是使用 subRouter 作为过滤器:

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);

这篇关于vert.x 有集中过滤吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆