import fetch from "node-fetch";
// ...
let statusCode = 500;
fetch(remoteUrl.toString(), {
headers: filterHeaders(req, req.headers),
agent: proxy // I do not know whether correct or not to set proxy here
}).then((responseStream) => {
statusCode = responseStream.status;
res.header(filterHeaders(req, responseStream.headers));
return responseStream.arrayBuffer(); // use `arrayBuffer()` to pipe responseBody in raw bytes format
}).then((responseBody) => {
res.status(statusCode).send(responseBody);
}).catch((err) => {
// How to handle error?
})
Hi, I am planning to remove the old dependency
request
, since it is deprecated for 2 years, and I prefer to usenode-fetch
to instead of it.There are two things confused me:
proxy
param is? Is it a URL string?Will be:
Thanks!