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.

Hi, I’m trying to proxy some requests during development to avoid cors issues but getting this error:

Access to XMLHttpRequest at 'https://gateway.boaconsulta.com/api/v1/cep/01322-050' (redirected from 'http://localhost:3000/cep/01322-050') from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

My nuxt.config.js is configured as follow:

axios: {
  proxy: true
},
proxy: {
  '/cep/': { target: 'http://gateway.boaconsulta.com/api/v1/' }
},

I’m calling the service this way on the client side:

async resolveCep () {
  await this.$axios.get(`/cep/${this.data.zip}`)
}

I see on Chrome devtools the origin header to the target url is still http://localhost:3000, but the changeOrigin option isn’t about rewrite the origin header to the target url?

What I’m doing wrong?

Appreciate any help.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

9reactions
paulogrcommented, Apr 15, 2020

sorry, my bad

5reactions
legitYosalcommented, Aug 6, 2020

oh ok! I accept it is very shameful to post the solution but the problem for me solved with changing

fetch(document.location.origin + '/api/auth/login/', {

to

fetch(document.location.origin + '/api/auth/login', {

*** notice deleting / from end of url 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cross-Origin Resource Sharing (CORS) - MDN Web Docs
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, ...
Read more >
A Guide to Solving Those Mystifying CORS Issues
An 'issue with CORS' occurs when the API does not reply to such request with, 'Yes, dear browser, you are allowed to do...
Read more >
What is CORS (cross-origin resource sharing)?
Vulnerabilities arising from CORS configuration issues · Server-generated ACAO header from client-specified Origin header · Errors parsing Origin headers.
Read more >
CORS errors and how to solve them
Or, your API fails and shows a CORS error in the console. · This happens because the same-origin policy is part of the...
Read more >
What Is a CORS Error and How to Fix It (3 Ways)
As a CORS error occurs when the external API server doesn't return the HTTP headers required by the CORS standard, you can add...
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