Electron-vue: How to config proxyTable for CORS

Created on 8 Sep 2017  ·  2Comments  ·  Source: SimulatedGREG/electron-vue

I use :

// dev-runner.js:startRenderer ()

const server = new WebpackDevServer(
      compiler,
      {
        contentBase: path.join(__dirname, '../'),
        quiet: true,
        setup (app, ctx) {
          app.use(hotMiddleware)
          ctx.middleware.waitUntilValid(() => {
            resolve()
          })
        },
        proxy: {
          '*' : {
            changeOrigin: true,
            target: 'http://127.0.0.1:8000'
          }
        }
      }
    )

error log:

XMLHttpRequest cannot load http://127.0.0.1:8000/api/v2/users. No 'Access-Control-Allow-Origin' 
header is present on the requested resource. 
Origin 'http://localhost:9080' is therefore not allowed access.

How to config proxyTable for CORS ?

thanks.

Most helpful comment

insert webPreferences: {webSecurity: false} at new BrowserWindow()

like this:

mainWindow = new BrowserWindow({
    height: 563,
    useContentSize: true,
    width: 1000,
    frame: false,
    webPreferences: {webSecurity: false}
  })

All 2 comments

axios call:

this.$http.get('http://127.0.0.1:8000/api/v2/users', qs.stringify({
        headers: {
          'Access-Control-Allow-Origin': '*'
        }
      })).then(response => {
        // success callback
        console.log(response)
      }, response => {
        // error callback
        console.log(response)
      })

and servcie already config.

insert webPreferences: {webSecurity: false} at new BrowserWindow()

like this:

mainWindow = new BrowserWindow({
    height: 563,
    useContentSize: true,
    width: 1000,
    frame: false,
    webPreferences: {webSecurity: false}
  })
Was this page helpful?
0 / 5 - 0 ratings

Related issues

michalzaq12 picture michalzaq12  ·  3Comments

oscar-g picture oscar-g  ·  3Comments

iwen-pengh picture iwen-pengh  ·  3Comments

rodrigomata picture rodrigomata  ·  3Comments

xiaomizhou66 picture xiaomizhou66  ·  3Comments