4

I used vuejs, with address http://localhost:8000.

When calling api, I get CORS error. Sid not succeed request headers request

Domain from origin http://localhost:8080 has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

let headers = {
          'Content-Type': 'application/json',
          'Access-Control-Allow-Origin': true,
};
4

2 Answers 2

3

You need to create a "vue.config.js" with proxy configuration.

Example :

 module.exports = {
  devServer: {
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        ws: true,
        changeOrigin: true
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

This will only work for OP's local dev server. It also means all the requests will need to be to relative /api URLs. localhost:8080 is OP's client-side service, not the API
what does 'ws: true' stand for?
-1

Three Options

Option 1. Edit Vue.config.js

 module.exports = {
      devServer: {
        proxy: {
          '/api': {
            target: 'http://localhost:8081',
            ws: true,
            changeOrigin: true
          }
        }
      }
    }

Option 2 (Temporary/Test use case)

  1. Use Cors Plugin in chrome Eg- Moseif CORS
  2. Degrade your chrome version less than 71
  3. Use chromium or Canary Browser.

Option 3

  1. Look into your server Cors allowed or not you can add plugin for python cors and annotation for java on server to allow this call.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.