How to set proxy in electron use webpack?

71 Views Asked by At

I'm using electron-react-boilerplate

set proxy in webpack devServer, but not work

The directory structure of this project is as follows:

enter image description here

use axios

const BASE_URL = process.env.NODE_ENV !== 'production' ? ORIGIN + '/api' : ORIGIN;

const instance = axios.create({
  baseURL: BASE_URL,
  timeout: 50000,
});

webpack.config.render.dev.ts


devServer: {
    port,
    compress: true,
    hot: true,
    // headers: { 'Access-Control-Allow-Origin': '*' },
    headers: {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
      'Access-Control-Allow-Headers':
        'X-Requested-With, content-type, Authorization',
    },
    static: {
      publicPath: '/',
    },
    proxy: {
      '/api': {
        target: 'http://xxx.xx.xx.xxx:18080',
        pathRewrite: { '^/api': '' },
        changeOrigin: true,
      },
    },
    ...
}

but not work: enter image description here

Is there an error in my configuration?

0

There are 0 best solutions below