gpt4 book ai didi

reactjs - tomcat apache 8 服务器上的 Pentaho API(端口 - 8080)在通过不同的 Web 应用程序(react JS,端口 - 3000)调用时会出现 COR 问题

转载 作者:行者123 更新时间:2023-12-04 08:32:31 25 4
gpt4 key购买 nike

我被困在一个点,我必须调用 pentaho API 来验证来自 reactJS 应用程序的用户。两者都在我的本地机器上。到目前为止我尝试过的事情:
a) 在 reactJS 配置文件 - package.json 中添加一个代理。
问题 - 代码命中 localhost:3000 而不是 localhost:8080
b) 在不安全的情况下启动谷歌浏览器并添加标题。
上面建议的链接 2 - How to allow CORS in react.js?
c) 在 pentaho 端修改 web.xml 文件并添加 cors jar 文件。
问题 - 我从 Maven 存储库下载了 cors jar 文件。添加了相应的过滤器。这些更改后服务器未启动。
链接 - https://www.ease2code.com/embedding-pentaho-cde-dashboard-in-web-application/
版本 - Pentaho 8.3 和 tomcat 8
错误 -
从源“http://localhost:3000”访问“http://localhost:8080/pentaho/j_spring_security_check”的 XMLHttpRequest 已被 CORS 策略阻止:没有“Access-Control-Allow-Origin” header 存在于请求的资源。

最佳答案

这终于奏效了。我们需要添加2个jar文件:

  • cors-filter-2.6
  • java-property-utils-1.13

  • 然后更新 webapps\pentaho\WEB-INF\web.xml 文件来读取这些 jars。
            <filter-name>CORS</filter-name>

    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>

    <init-param>

    <param-name>cors.allowOrigin</param-name>

    <!-- Update specific domains instead of giving to all -->

    <param-value>*</param-value>

    </init-param>

    <init-param>

    <param-name>cors.supportsCredentials</param-name>

    <param-value>false</param-value>

    </init-param>

    <init-param>

    <param-name>cors.supportedHeaders</param-name>

    <param-value>accept, authorization, origin</param-value>

    </init-param>

    <init-param>

    <param-name>cors.supportedMethods</param-name>

    <param-value>GET, POST, HEAD, OPTIONS</param-value>

    </init-param>

    </filter>

    <filter-mapping>

    <filter-name>CORS</filter-name>

    <url-pattern>/*</url-pattern>

    </filter-mapping>
    重启 pentaho 服务器。它会工作

    关于reactjs - tomcat apache 8 服务器上的 Pentaho API(端口 - 8080)在通过不同的 Web 应用程序(react JS,端口 - 3000)调用时会出现 COR 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64957882/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com