Webpack setting reverse proxy is invalid

webpack.dev.conf.js

const path = require("path"),
  webpack = require("webpack"),
  UglifyJSPlugin = require("uglifyjs-webpack-plugin"),
  HtmlWebpackPlugin = require("html-webpack-plugin"),
  config = require("./webpack.base.conf.js");

config.devServer = {
  port: "9500",
  host: "localhost",
  historyApiFallback: true,
  watchOptions: {
    aggregateTimeout: 300,
    poll: 1000
  },
  contentBase: path.join(__dirname, "../dist"),
  // hot: true,
  proxy: {
    "/api": {
      target: "http://baidu.com",
      secure: false,
      changeOrigin: true,
      pathRewrite: {
        "^/api": ""
      }
    }
  }
}

config.plugins = (config.plugins || []).concat([
  // new webpack.HotModuleReplacementPlugin(),
  new webpack.NamedModulesPlugin(),
  new HtmlWebpackPlugin({
    title: "CMS-FE DEV",
    filename: "index.html",
    template: "src/template/index_base.html",
    // template: "dist/index.html",
  })
]);

module.exports = config;

  public getCarList (data: any) {
      return this.http.get(`/api/car/car-list`, {
      params: data,
    });
    // return this.carList;
  }
  }

clipboard.png

Mar.23,2021

http://baidu.com/car/car-list will appear 302ah
you can try

this.http.get(`/api/s`, {
    params: {
        wd: 'test'
    }
});

check whether the http status code is 200

Menu