使用 Webpack 开发服务器进行 301 重定向

Cos*_*tin 5 http-status-code-301 webpack webpack-dev-server

我正在尝试从此格式重定向网址:

http://localhost:8080/setup/xyz/?code=some-code

对此:

http://localhost:8080/app/#/setup/xyz/?code=some-code

我已经尝试过代理和重写:

historyApiFallback: {
  rewrites: [
    { from: /^\/$/, to: '/index.html' },
    { from: /^\/app/, to: '/app.html' },
    { from: /^\/setup/, to: '/app/#/setup' },
  ]
Run Code Online (Sandbox Code Playgroud)

},

但它似乎不起作用。有没有办法使用开发服务器编写 301 重定向?

Eug*_*kov 0

尝试配置devServer https://itsopensource.com/how-to-serve-api-locally-with-webpack/

const data = require("./data.json");

module.exports = {
  mode: "development",
  entry: "./src/index",
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "build")
  },
  plugins: [],
  devServer: {
    before: function(app) {
      app.get("/getData", function(req, res) {
        res.json(data);
      });
    },
    open: true,
    port: 3000
  },
  resolve: {
    extensions: [".js"]
  },
  module: {}
};
Run Code Online (Sandbox Code Playgroud)