我的API它在另一个域下运行..我正在尝试用Vercel配置代理..
它向/api/test.json发出请求的应用程序,所以我试着...关于vercel配置
"redirects": [
{
"source": "/api/test.json",
"destination": "https://myapi.com/test.json",
}
],
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.html"
}
]我收到了来自/api/test.json的404
发布于 2021-01-27 22:40:41
只需使用重写
"rewrites": [
{
"source": "/api/test.json",
"destination": "https://myapi.com/test.json",
}
]然后在你的应用程序中
httpAgent
.get('/api/test.json)
.then(res => { console.log(res) })发布于 2021-07-03 06:02:28
使用wildcard path matching :path*语法:
// in vercel.json:
// for example proxying /api/ → https://backend-endpoint/
{
"rewrites": [
{
"source": "/api/:path*",
"destination": "https://backend-endpoint/:path*"
},
{
"source": "/api/:path*/",
"destination": "https://backend-endpoint/:path*/"
}
]
}注意:为了让事情正常工作,你需要在上面的rewrites 数组下使用两个完全相同的对象。documentation中的示例只是一个没有尾随斜杠的示例,它不会将(例如) /api/auth/login/转换为https://backend-endpoint/auth/login/,该示例只能将/api/auth/login转换为https://backend-endpoint/auth/login (没有尾随斜杠/)
(我花了一天时间才意识到尾随斜杠/实际上非常重要)。
https://stackoverflow.com/questions/65456701
复制相似问题