proxy - 如何使用 Vercel 设置代理

标签 proxy vercel

我的 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

最佳答案

简单地使用重写

"rewrites": [
    {
        "source": "/api/test.json",
        "destination": "https://myapi.com/test.json",
    }
]
然后在您的应用程序中
httpAgent
  .get('/api/test.json)
  .then(res => { console.log(res) })

关于proxy - 如何使用 Vercel 设置代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65456701/

相关文章:

preact - 在 SSR 中同时渲染多个 preact-router 路由(在 Vercel 上)

javascript - 这是 Vercel 错误吗?找不到模块 './model'

javascript - 为什么不响应代理请求

node.js - 网络代理阻止socket.io

http - 用于评估 PAC 代理配置文件的库?

node.js - 跟踪通过 clearnet/Cloudflare/Apache 的请求以精确找出性能问题

java - 使用 Java 的 htmlunit.WebClient 和多个代理进行多线程处理

reactjs - 部署使用 Vercel 或 Nextjs 重写配置的项目后找不到 Assets 路径

node.js - 如何修复错误 : SQLITE_CANTOPEN: unable to open database on Zeit. co?

next.js - 无法在 Vercel 上使用 serverSideTranslations