简体   繁体   中英

Configuring CORS at WSO2 microintegrator with Integrator Studio

I have setup some API for angular consumption, but I get CORS issues from prefligth options. I set up an API for OPTIONS and an API for POST.

Reading here and there, I got this:

<property description="Request-Headers" name="Access-Control-Request-Headers" scope="transport" type="STRING" value="*"/>
<property description="Allow-Methods" name="Access-Control-Allow-Methods" scope="transport" type="STRING" value="OPTIONS POST"/>
<property description="Allow-Headers" name="Access-Control-Allow-Headers" scope="transport" type="STRING" value="*"/>
<property description="Allow-Origin" name="Access-Control-Allow-Origin" scope="transport" type="STRING" value="*"/>
<property description="application-json" name="ContentType" scope="axis2" type="STRING" value="application/json"/>
<property description="RESPONSE" name="RESPONSE" scope="default" type="STRING" value="true"/>

The request get property logged to a log mediator to the option api, but when I test the api, my configuration isn't set:

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: 
Access-Control-Request-Headers: *
Host: localhost:8290
Access-Control-Allow-Headers: content-type
Content-Type: text/plain; charset=UTF-8
Date: Tue, 10 Nov 2020 01:17:25 GMT
Transfer-Encoding: chunked

{ 
    "status":  "ok"
}

Specifically Allow-Methods is my principal concern

If you are using WSO2 EI V7.xx or V8.xx, just add the following configuration to the <EI_HOME>/runtime/microesb/conf/deployment.toml file.

[synapse_properties]
'synapse.rest.CORSConfig.enabled' = "true"
'synapse.rest.CORSConfig.Access-Control-Allow-Origin' = "http://127.0.0.1:5500, http://localhost:5500"
'synapse.rest.CORSConfig.Access-Control-Allow-Methods' = "GET, POST, PUT, DELETE, HEAD, OPTIONS"
'synapse.rest.CORSConfig.Access-Control-Allow-Headers' = "content-type, Accept, Authorization"

Change the Allowed origin, methods, and headers according to your need.

For WSO2 EI v6.xx, check out https://docs.wso2.com/display/EI660/Enabling+CORS+for+Data+Services+

Also, try to specify your frontend base url in the allowed origin header instead of "*"

我发现的最简单的方法是将 cors 身份验证用于 nginx,并使用 nginx 作为 wso2 前面的负载均衡器...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM