这是一个简单的 CORS 代理服务,帮助你解决跨域请求问题。
https://your-domain.vercel.app/api/proxy?url=目标网址https://your-domain.vercel.app/api/proxy?url=https://jsonplaceholder.typicode.com/posts/1// GET 请求
fetch('/api/proxy?url=https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data));
// POST 请求
fetch('/api/proxy?url=https://api.example.com/data', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ key: 'value' })
})
.then(response => response.json())
.then(data => console.log(data));