如何在我的 proxy.conf.json 中定义代理的多个路径? angular-cli proxy documentation在 github 上看起来你只能有一个路径 (/api):
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}
但是当我查看 webpack proxy或 http-proxy-middleware文档,我看到应该可以定义多个路径(/api-v1 和/api-v2):
// Multiple entry
proxy: [
{
context: ['/api-v1/**', '/api-v2/**'],
target: 'https://other-server.example.com',
secure: false
}
]
但我不明白如何将它放入 proxy.conf.json 中。
最佳答案
在您的 proxy.conf.json 中使用以下语法:
[
{
"context": ["/api-v1/**", "/api-v2/**"],
"target": "https://other-server.example.com",
"secure": false
}
]
实际的语法如下:
[
{
"context": [
"/api",
"/other-uri"
],
"target": "http://localhost:8080",
"secure": false
}
]
关于angular - 使用具有多路径代理匹配的 angular-cli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44494012/