gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:03:42 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com