我正在使用带有APIKit + RAML的Mule 3.7。缺乏有关mule的http响应构建器的文档,等等。
Http凭证不支持Access-Control-Allow-Origin的通配符,因此需要去掉通配符,并将该值动态设置为消息头中的原始值。
错误:当credentials标志为true时,不能在'Access-Control-Allow-Origin‘标头中使用通配符'*’。因此不允许访问源'http://localhost:8080‘。
如何将Access-Control-Allow-Origin值设置为#[message.inbound‘Origin’]
<flow name="api-main">
<http:listener config-ref="api-httpListenerConfig" path="/api/*" doc:name="HTTP">
<http:response-builder>
<http:header headerName="Access-Control-Allow-Origin" value="*"/>
</http:response-builder>
</http:listener>
<apikit:router config-ref="api-main-config" doc:name="APIkit Router"/>
<exception-strategy ref="component-registry-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/>
</flow>发布于 2017-01-07 14:02:10
这个问题不仅仅是向响应报头添加报头。
如果您将allow credentials头部设置为true,则实际浏览器会将带有OPTION方法的印前检查请求发送到test,并允许源跨域请求。请参阅:https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
仅设置Access-Control-Allow-Origin响应头将不起作用。
<set-property propertyName="Access-Control-Allow-Origin" value="*">幸运的是,有一个用于处理CORS请求的mule模块,但它缺乏文档。您需要在app.xml的开头设置此配置。
<cors:config name="Cors_Configuration" doc:name="Cors Configuration">
<cors:origins>
<cors:origin url="http://localhost:8080">
<cors:methods>
<cors:method>POST</cors:method>
<cors:method>DELETE</cors:method>
<cors:method>PUT</cors:method>
<cors:method>GET</cors:method>
</cors:methods>
<cors:headers>
<cors:header>content-type</cors:header>
</cors:headers>
</cors:origin>
</cors:origins>
</cors:config>并在APIkit路由器之前使用它。
<http:inbound-endpoint address="http://localhost:8081/api" doc:name="HTTP" exchange-pattern="request-response"/>
<cors:validate config-ref="Cors_Configuration" publicResource="false" acceptsCredentials="true" doc:name="CORS Validate”/>
<apikit:router config-ref=“apiConfig" doc:name="APIkit Router”/>注意:实际上你需要手动下载mule-cors.xsd定义文件,并复制到/resources文件夹。将此xmlns和xsi附加到app.xml
<mule xmlns:cors="http://www.mulesoft.org/schema/mule/cors"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/cors classpath:/mule-cors.xsd" >mule-cors.xsd:https://github.com/mulesoft/mule-module-cors/blob/master/src/main/resources/META-INF/mule-cors.xsd
发布于 2016-03-02 00:08:35
只需在apikit路由器后面使用set property组件,以这种方式添加头部。
<set-property propertyName="Access-Control-Allow-Origin" value="*">HTTP连接器在应答时将转换标头中的所有出站属性。
https://stackoverflow.com/questions/35162476
复制相似问题