如何使用fiori-tools-proxy替换请求路径前缀
解决方案:通过fiori-tools-proxy实现路径前缀替换
要实现将/DEST开头的请求前缀替换为/sap后代理到后端,需要在fiori-tools-proxy的后端配置中添加路径重写规则,这依赖于其底层使用的http-proxy-middleware的pathRewrite参数。
修改后的代理配置
在你的ui5.yaml的backend节点中添加pathRewrite配置:
backend: - path: /DEST url: https://myurl:8001 client: "500" pathRewrite: {"^/DEST": "/sap"}
完整的fiori-tools-proxy配置片段
server: customMiddleware: - name: fiori-tools-proxy afterMiddleware: compression configuration: ignoreCertError: true ui5: path: - /resources - /test-resources url: https://ui5.sap.com backend: - path: /DEST url: https://myurl:8001 client: "500" pathRewrite: {"^/DEST": "/sap"}
规则说明
pathRewrite中的"^/DEST": "/sap"是正则匹配规则:^/DEST表示匹配所有以/DEST开头的请求路径- 匹配到的部分会被替换为
/sap
- 最终效果:
/DEST/opu/odata/sap/...会被代理到https://myurl:8001/sap/opu/odata/sap/...,完全符合需求。
注意事项
- 该配置无需修改前端请求路径,完全在代理层完成前缀替换,适配你无法修改请求路径的项目限制。
pathRewrite是http-proxy-middleware的标准配置,fiori-tools-proxy会直接传递该参数给底层代理。
内容的提问来源于stack exchange,提问作者Mada
相关产品推荐
相关产品推荐

