使用 http-proxy-middleware 重写路径
Rewriting path with http-proxy-middleware
正在尝试使用 http-proxy-middleware 重写请求路径。但麻烦的是,当我写这样的代码时:
proxyMiddleware('/service/api', {target: 'http://192.168.70.99:8078/'});
表示像/service/api/export/1这样的路径会被重定向到http://192.168.70.99:8078/service/api/export/1; But I need to redirect it to http://192.168.70.99:8078/export/1。我该怎么做?
您可以传递 pathRewrite
opiton 并在其中使用正则表达式模式删除不需要的路径:
proxyMiddleware('/service/api', {
target: 'http://192.168.70.99:8078/',
pathRewrite: {
'^/service/api':'' //remove /service/api
}
});
正在尝试使用 http-proxy-middleware 重写请求路径。但麻烦的是,当我写这样的代码时:
proxyMiddleware('/service/api', {target: 'http://192.168.70.99:8078/'});
表示像/service/api/export/1这样的路径会被重定向到http://192.168.70.99:8078/service/api/export/1; But I need to redirect it to http://192.168.70.99:8078/export/1。我该怎么做?
您可以传递 pathRewrite
opiton 并在其中使用正则表达式模式删除不需要的路径:
proxyMiddleware('/service/api', {
target: 'http://192.168.70.99:8078/',
pathRewrite: {
'^/service/api':'' //remove /service/api
}
});