webpack-dev-server在https上开发

时间:2017-01-19 13:22:20

标签: reactjs websocket webpack webpack-dev-server

我的.NET Core API通过https公开。

我想从我在webpack-dev-server上运行的React应用程序请求API。但默认情况下webpack-dev-server在http上运行,CORS阻止任何请求。

我重新配置webpack以强制使用https(使用我的* .pfx证书example), 但后来我发现了私人连接错误'在浏览器中每次刷新(次要问题)并且自动刷新停止工作。

控制台错误:

RunRequest

我认为webpack-dev-server的websockets因为https url而无法建立连接。但我不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

在您的webpack dev server config

中代理您的.NET核心API
{
  proxy: {
    '/api/**': {
      target: 'https://localhost:443', // or whichever port it's listening on
      secure: false,
      changeOrigin: true, // this might not be necessary depending on how restrictive your host is
      pathRewrite: {'^/api' : ''}, // rewrite request /api/foo -> https://localhost:443/foo
    },
  }
}

有关使用webpack dev服务器进行代理的更多文档:
https://webpack.github.io/docs/webpack-dev-server.html#proxy

相关问题