我正在构建一个Angular 4应用程序,它使用REST API与Camunda进程交互。尝试登录,面临CORS错误。
Dockerfile:
FROM camunda/camunda-bpm-platform:tomcat-latest
ADD sample.war /camunda/webapps/sample.war
COPY ./web.xml /camunda/webapps/engine-rest/WEB-INF
像以下一样运行:
docker build -t camunda-eval .
docker run -d --name camunda -p 8080:8080 <image>
控制台出错:
无法加载 http://localhost:8080/camunda/api/admin/auth/user/default/login/tasklist: 请求中不存在“Access-Control-Allow-Origin”标头 资源。因此不允许来源“http://localhost:4200” 访问。
我的web.xml如下所示:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>EmptyBodyFilter</filter-name>
<filter-class>org.camunda.bpm.engine.rest.filter.EmptyBodyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>EmptyBodyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CacheControlFilter</filter-name>
<filter-class>org.camunda.bpm.engine.rest.filter.CacheControlFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CacheControlFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Http Basic Authentication Filter -->
<!-- <filter>
<filter-name>camunda-auth</filter-name>
<filter-class>
org.camunda.bpm.engine.rest.security.auth.ProcessEngineAuthenticationFilter
</filter-class>
<init-param>
<param-name>authentication-provider</param-name>
<param-value>org.camunda.bpm.engine.rest.security.auth.impl.HttpBasicAuthenticationProvider</param-value>
</init-param>
<init-param>
<param-name>rest-url-pattern-prefix</param-name>
<param-value></param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>camunda-auth</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> -->
<filter>
<filter-name>Resteasy</filter-name>
<filter-class>
org.jboss.resteasy.plugins.server.servlet.FilterDispatcher
</filter-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.camunda.bpm.engine.rest.impl.application.DefaultApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Resteasy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.preflight.maxage</param-name>
<param-value>10</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
有关如何解决此问题的任何想法?
答案 0 :(得分:3)
您收到此错误是因为“localhost:4200”和“localhost:8080”与CORS不同。
一般来说,您有3种方法可以避免这种情况:
chromium-browser --disable-web-security --user-data-dir
) - 如果您只想玩游戏,这是最快的,但当然没有生产解决方案