cancel
Showing results for 
Search instead for 
Did you mean: 

API Gateway CORS configuration

JoergAldinger
Active Contributor
0 Kudos

Hello all, hello ankit.chauhan1 ,

We are trying to use the API Gateway to generate PDF documents. However, we are using a web application so we need to be able to configure CORS in a way similar to how it is done in Service Layer.

The documentation doesn't mention the CORS issue at all.

Can you point us in the right direction, please?

Thanks and best regards,

Joerg.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Dear joerg.ceo,

Following link should help you: https://cloud.spring.io/spring-cloud-gateway/multi/multi__cors_configuration.html

Currently, there seems no convenient way to enable CORS in config file.

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

JoergAldinger
Active Contributor
0 Kudos

Thank you ankit.chauhan1.

Since we didn't find a way to do this, we set up the CORS cofiguration on a reverse proxy and decided to put the API Gateway behind it. And that worked fine.

Thanks again.

Joerg.

srikanthin
Participant
0 Kudos

Hi Joerg,

Can you please help me out with what reverse proxy rules you have used to overcome the CORS issue.

Regards,

Srikanth

JoergAldinger
Active Contributor
0 Kudos

Hello srikanthin

If using nginx, try the following:

add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
proxy_pass https://127.0.0.1:60000/;
proxy_cookie_flags SESSION "SameSite=None";

Our actual configuration is a little more extensive because we run different applications and services through the same server, but this should point you in the right direction of what you need.

Hope this helps.

Best regards,

Joerg.

srikanthin
Participant
0 Kudos

Hi Joerg,

Thanks for the response, even we run different applications on the same server. We have a xsjs web application which runs on HANA database in that application we call this API Gateway service to generate PDF and we are getting CORS issue.

I will try nginx configuration which you have provided.

Regards,

Srikanth

JoergAldinger
Active Contributor
0 Kudos

Hello srikanthin ,

I don't think you should have any CORS issues if you're issuing a server call from HANA XS Engine straight to the API gateway. CORS is really only coming into play when the browser itself is issuing the request to the API gateway, which is our scenario.

Best regards,

Joerg.

rahuljain257
Participant
0 Kudos

Hello joerg.ceo

Thanks for sharing the sample code but when I added the below code in the conf.d file I came across the following error -

proxy_cookie_flags SWSSION "SameSite=None"

JoergAldinger
Active Contributor
0 Kudos

Hello rahul.jain257

proxy_cookie_flags was introduced in nginx version 1.19.3. Please make sure you are running at least that version. See here: Module ngx_http_proxy_module (nginx.org)

Hope this helps,

Joerg.

Accepted Solutions (0)

Answers (0)