2016-02-02 26 views
1

林。缺少關於mule的http響應構建器等的文檔。騾3.7 Apikit CORS - 訪問控制允許來源使用騾3.7與APIKit + RAML

Http憑證不適用於Access-Control-Allow-Origin的通配符,因此需要刪除通配符,並將該值動態設置爲消息頭中的原點。

錯誤: 當憑證標誌爲true時,通配符'*'不能用於'Access-Control-Allow-Origin'標頭。因此不允許訪問原產地'http://localhost:8080'。

如何設置訪問控制允許來源值#[message.inboundProperties [「原點」]

<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> 
+0

你好,對不起,但不知道我理解你的要求。要覆蓋頭部訪問控制允許來源上的HTTP請求到您的API覆蓋哪些客戶端發送或者要覆蓋頭部的響應回答了客戶的時候呢? –

+0

在響應中回答客戶端時覆蓋標題。 – mnouh1

+0

這個問題不應該是具體到騾子版本,好像這個問題和解決方案可以適用於新版本 – mCeviker

回答

1

只需使用一組特性部件的apikit路由器後添加頁眉通過這種方式。

<set-property propertyName="Access-Control-Allow-Origin" value="*"> 

應答時的HTTP連接器將轉換標頭中的所有出站屬性。

3

此問題是比將報頭添加到響應頭以上。

如果您正在設置允許憑證頭爲真,實際的瀏覽器會發送一個預檢要求與OPTION的方法來「測試」,並允許起源跨域請求。參考: 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請求,但它缺乏文檔。您需要在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」/> 

注:其實你需要手動下載騾子cors.xsd定義文件,並複製到/資源文件夾中。這個附加的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" > 

騾子cors.xsd:https://github.com/mulesoft/mule-module-cors/blob/master/src/main/resources/META-INF/mule-cors.xsd

參考文獻:https://github.com/mulesoft/apikit/issues/27

相關問題