【问题标题】:301 redirect with Webpack dev server使用 Webpack 开发服务器进行 301 重定向
【发布时间】:2018-08-09 20:02:29
【问题描述】:

我正在尝试以这种格式重定向网址:

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' },
  ]

},

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

【问题讨论】:

    标签: webpack webpack-dev-server http-status-code-301


    【解决方案1】:

    尝试配置devServerhttps://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: {}
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      • 1970-01-01
      • 2014-08-30
      • 2017-04-15
      • 2018-03-09
      • 2015-08-15
      • 2014-02-03
      相关资源
      最近更新 更多