How do I enable CORS?
Problem
Serverless Framework Version: 1.0.0-beta.1.1 How do I enable CORS so I can access my functions? I can't find anything in the docs, and the CORS plugin seems to not be relevant to the current version of Serverless.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: How do I enable CORS?
Hi Serverless Team, I really like serverless! I was able to quickly get a couple of API's running. I, unfortunately, am having a CORS problem with the API's and Angular 2. XMLHttpRequest cannot load https://s7t6o3hx8l.execute-api.us-east-1.amazonaws.com/dev/notes. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowe
Trust Score
4 verifications
- 1
I really like serverless! I was able to quickly get a couple of API's running. I
I really like serverless! I was able to quickly get a couple of API's running. I, unfortunately, am having a CORS problem with the API's and Angular 2.
- 2
XMLHttpRequest cannot load https://s7t6o3hx8l.execute-api.us-east-1.amazonaws.co
XMLHttpRequest cannot load https://s7t6o3hx8l.execute-api.us-east-1.amazonaws.com/dev/notes. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
- 3
I using the { 'Content-Type': 'application/json' } in the header for my GET from
Access-Control-Allow-Headers 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token' Access-Control-Allow-Methods 'OPTIONS,GET,POST' Access-Control-Allow-Origin '*'
- 4
Still I cannot get this to work. Usually I develop REST API's with Node.js and E
Still I cannot get this to work. Usually I develop REST API's with Node.js and Express. I use the CORS node.js package to enable CORS. With this I have never had the issue described above.
Validation
Resolved in serverless/serverless GitHub issue #1955. Community reactions: 7 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep