vue cli3 enable CORS

Code Tree picture Code Tree · Feb 19, 2019 · Viewed 9.9k times · Source

I have had this problem for nearly 2 days, any help would be a life saver.

I have my vue app running on 8080 dev mode and I am trying to integrate blockstack login and that app tries to read http://localhost/manifest.json, so I placed it in static directory, but it is throwing me cors error, do we have solution for that vue cli configurations like vue.config.js?

Answer

CorbinUX picture CorbinUX · Dec 3, 2019

The "correct answer" doesn't actually help in this instance.

Blockstack needs to be able to hit the manifest.json file (in this case localhost:8080/manifest.json). When the server doesn't support CORS Blockstack will throw an error.

What the OP is asking is how to make "vue-cli-service serve" allow COR requests to happen. To do this, we need to modify Webpack's dev server to allow the CORS request.

Add vue.config.js (if it doesn't already exist)

module.exports = {
  configureWebpack: {
    devServer: {
      headers: { "Access-Control-Allow-Origin": "*" }
    }
  }
};