Multiple CORS origins

According to the documentation at https://www.serverless.com/framework/docs/providers/aws/events/apigateway/#enabling-cors I should be able to add multiple origins to the cors definition:

          cors:
             origins:
                - http://example.com
                - http://example2.com

and then mentioned that a response template will be used to return the correct one in the Access-Control-Allow-Origin header. However, when I do this I simply get both values returned and the browser throws a fit.

Is the response template not automatically generated? Should I add it myself to serverless.yaml? Is there an example somewhere I can have a look at?

Thanks,
Eddie

1 Like

I worked on that issue and the following lines worked for me:

cors:
origin: “https:// www . example . com,https:// example . com,https:// dev . example . com”
headers:
- Accept
- Referer
- Session-Token
- User-Agent
- X-XSRF-TOKEN
allowCredentials: true

But the third origin (https:// dev . example . com) throws me a CORS error. The first two origins worked well.

(I have putted spaces between URLs because as a new user I’m not allowed to put URLs)

Hope it helps

Hi, no answers to that please ? No one know how to solve that ?

ShowBox Tutuapp Mobdro