asddsa
asddsa

Reputation: 23

How to fix CORS policy issue with get request?

please help me to solve CORS policy issue, it happens when I'm trying to make a get request to applications endpoint, and issue is only reproducible from http://localhost:8080/ on prod request works fine.

vue.config.js file

module.exports = {
    devServer: {
        proxy: 'https://spinstatus.zenoss.io/'
    }
}

request method

const grabApps = async () => {
  const res = await axios({
    method: 'get',
    url: `${spinnakerURL}/gate/applications`,
    withCredentials: false,
    crossdomain: true,
    headers: {
      'Access-Control-Allow-Origin': '*',
    }
  });
  return res.data || []
}

error

headers from localhost request

headers from prod request

Upvotes: 0

Views: 575

Answers (1)

IVO GELOV
IVO GELOV

Reputation: 14259

Change the devServer configuration in vue.config.js like this:

module.exports = {
  devServer:
  {
    proxy:
    {
      '/gate':
      {
        target: 'https://spinstatus.zenoss.io',
        changeOrigin: true,
        onProxyReq: (proxyReq, req, res, options) =>
        {
          proxyReq.setHeader('Origin', 'https://spinstatus.zenoss.io');
        }
      }
    }
  }
};

Upvotes: 1

Related Questions