CORS not working
See original GitHub issueI’m facing an issue when trying to access one of my microservices behind the express-gateway on a localhost:
Failed to load http://localhost:8080/data: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8888' is therefore not allowed access.
My gateway.config.yml
http:
port: 8080
admin:
port: 9876
hostname: localhost
apiEndpoints:
data-api:
host: localhost
methods: 'GET,POST,PUT'
paths: '/data'
product-api:
host: localhost
paths: '/products'
serviceEndpoints:
data-svc:
url: 'http://localhost:8282'
product-svc:
url: 'http://localhost:6000'
policies:
- cors
- jwt
- proxy
- rate-limit
pipelines:
data:
apiEndpoints:
- data-api
policies:
- cors:
- action:
origin: "*"
methods: 'HEAD,PUT,PATCH,POST,DELETE'
allowedHeaders: "Origin, X-Requested-With, Content-Type, Accept"
preflightContinue: true
- rate-limit:
- action: # allow
max: 10 # max 10 request
windowMs: 120000 # per 120 seconds
- jwt:
- action:
secretOrPublicKeyFile: ./key/pubKey.pem
checkCredentialExistence: false
products:
apiEndpoints:
- product-api
policies:
- proxy:
- action:
serviceEndpoint: product-svc
changeOrigin: true
Any suggestions?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
CORS errors and how to solve them - Topcoder
Open a network tab in your console. ... In the response header look for the Access-Control-Allow-Origin header. If it does not exist then...
Read more >CORS errors - HTTP - MDN Web Docs - Mozilla
If the CORS configuration isn't setup correctly, the browser console will present an error like "Cross-Origin Request Blocked: The Same Origin ...
Read more >3 Ways to Fix the CORS Error — and How the Access-Control ...
Fix one: install the Allow-Control-Allow-Origin plugin. The quickest fix you can make is to install the moesif CORS extension .
Read more >CORS not working on Chrome - Stack Overflow
CORS will work in chrome. Just use chrome is safe-mode, i.e., use disable security settings. Google ...
Read more >What Is a CORS Error and How to Fix It (3 Ways) - Bannerbear
Solution 1: Configure the Backend to Allow CORS · Solution 2: Use a Proxy Server · Solution 3: Bypass the Error Using a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@WesleyFaveri yeah it was like 1 year ago. I think the issue was I haven’t added
OPTIONS
method to the method list under policies. For a working example , please check this https://gist.github.com/NomadXD/05956bfe4158fee674d22fb7078cc5bbYes, i removed
methods
fromapiEndpoints: data-api: host: localhost methods: 'GET,POST,PUT' paths: '/data'
and it worked