他们在论坛上到处张贴这个 CORS 问题。这似乎很混乱。但最后一个解决方案说在标头中使用返回的 url,端点是我的服务器(不是 cloudflare;令人困惑的部分)。但是我一直在弄清楚这将如何工作,我的 nodejs 将创建什么样的请求以及我将如何传递目标 URL?
一些 api 调用它并获取 url。那太棒了。
const response = await fetch("https://api.cloudflare.com/client/v4/accounts/$ACCOUNT/stream?direct_user=true", {
method: 'POST',
headers: {
'Authorization': 'bearer $TOKEN',
'Tus-Resumable': '1.0.0',
'Upload-Length': request.headers.get('Upload-Length'),
'Upload-Metadata': request.headers.get('Upload-Metadata')
},
})
const destination = response.headers.get('Location')
然后目标需要附加到endpoint
包含此信息的标题上。如何将此信息添加到我的服务器?
return new Response(null, {
headers: {
'Access-Control-Expose-Headers': 'Location',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin':'*',
'Location': destination
}
})
我怎样才能通过目的地?
router.all('*', (req, res, next) => {
// how can I pass the destination to here? I tried adding query/body; that doesnt work
res.header("Access-Control-Allow-Origin", '*');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Credentials","true");
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.header('Tus-Resumable', '1.0.0');
res.header('Access-Control-Expose-Headers', 'Location');
return next();
});