【问题标题】:Ninja Framework preflightNinja 框架预检
【发布时间】:2019-12-19 11:17:33
【问题描述】:

在 Ninja Framework 中是否有特定的预检方式?

我正在尝试允许所有预检请求,但是由于我没有使用 options 方法的所有内容的路由,它出现为 404 并且失败。

基本上,我遇到了这个错误并试图摆脱它:

Access to XMLHttpRequest at 'https://example.com/path/to/endpoint' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

有没有办法捕获所有选项方法并允许它们?而不是用选项请求重写每条路由?

即而不是:

router.GET().route("/index.html").with(ApplicationController::index);
router.OPTIONS().route("/index.html").with(ApplicationController::index);
router.GET().route("/user").with(ApplicationController::user);
router.OPTIONS().route("/user").with(ApplicationController::user);

它应该是这样的(下面的伪代码):

router.OPTIONS().route(<All Routes>).respond("200 OK");

【问题讨论】:

    标签: java ninjaframework


    【解决方案1】:

    解决办法是这样的:

        router.OPTIONS().route("/.*").with(Controller::method);
    

    它现在捕获所有预检请求

    【讨论】:

      猜你喜欢
      • 2015-06-01
      • 1970-01-01
      • 2014-07-07
      • 2014-10-27
      • 2017-05-23
      • 2016-11-29
      • 2014-09-04
      • 2016-12-21
      • 1970-01-01
      相关资源
      最近更新 更多