webpack-dev-server仅代理“ localhost”请求

时间:2019-02-14 16:45:19

标签: webpack webpack-dev-server webpack-4

由于我更改了Axios基本URL,因此Webpack-dev-server代理已损坏。在我开始使用axiosInstance之前,它工作正常,因此从“ localhost:80”向“ localhost:8080”代理。以下是我的webpack.config.jsaxiosConfig.js模块。有人知道发生了什么吗?

请在此处找到具有最低配置的存储库,该存储库可再现行为:https://github.com/charlycou/webpack-dev-server-proxy-test

webpack.config.js

const webpackConfig = {
  mode: "development",
  devtool: "source-map",
  output: {
    path: path.join(__dirname, "/dist"),
    filename: "main.js"
  },
  devServer: {
    contentBase: path.join(__dirname, "public"),
    publicPath: "/dist/",
    port: 80,
    open: "Chrome",
    proxy: {
      // proxy all webpack dev-server requests starting with /observation to Spring Boot backend (localhost:8080)
      "/observation": "http://localhost:8080",
      changeOrigin: true
    }
  },
  module: {
    rules: [scssLoader, urlLoader, vueLoader]
  },
  plugins: [new VueLoaderPlugin()]
};
module.exports = webpackConfig;

axiosConfig.js

import Axios from "axios";
export let axiosInstance = Axios.create({
  baseURL: 'http://mydomain.fr:8080',
});

1 个答案:

答案 0 :(得分:0)

如果您使用的是72.0.3626.109-您是否尝试过其他浏览器?

我无法在最新的Chrome浏览器中使用代理,但对于IE11或FF来说一切正常。 顺便说一句,我不是完全在谈论Webpack-dev-server,但我也为代理感到困扰:(