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

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

我正在尝试从此格式重定向网址:
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 重定向?

最佳答案

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

关于webpack - 使用 Webpack 开发服务器进行 301 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49055008/

相关文章:

网页包 2 "exports is not defined"

node.js - "command not found: webpack-dev-server"的 webpack-dev-server 错误

apache - .htaccess 文件中哪个是正确/更好的规则?

http - 将用户重定向到特定国家/地区时,我应该发送哪个 HTTP 状态代码?

javascript - PhpStorm 中 JS Cookie 的代码补全

angular - webpack 中 JSON 文件的缓存清除

environment-variables - 使用webpack开发和生产环境变量

javascript - Karma 不运行测试用例

node.js - 模块内的 Webpack 未找到 Cheerio

http - "404 redirect"是合法的重定向吗?