question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’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:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
NomadXDcommented, Apr 3, 2021

@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/05956bfe4158fee674d22fb7078cc5bb

1reaction
TietjeDKcommented, Apr 17, 2018

Yes, i removed methods from apiEndpoints: data-api: host: localhost methods: 'GET,POST,PUT' paths: '/data' and it worked

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found