add error checking
All checks were successful
Publish Docker Images / docker (push) Successful in 1m16s
All checks were successful
Publish Docker Images / docker (push) Successful in 1m16s
This commit is contained in:
@ -27,37 +27,43 @@ export default class ProxyRoute extends Route {
|
||||
return;
|
||||
}
|
||||
// TODO: handle rate limiting? and/or caching?
|
||||
const response = await axios.get(url, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
const data = response.data;
|
||||
const headers = response.headers;
|
||||
try {
|
||||
const response = await axios.get(url, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
const data = response.data;
|
||||
const headers = response.headers;
|
||||
|
||||
// Is delete the best way to do this??
|
||||
// Remove CORS headers
|
||||
delete headers["access-control-allow-origin"];
|
||||
delete headers["access-control-allow-credentials"];
|
||||
delete headers["access-control-allow-headers"];
|
||||
delete headers["access-control-allow-methods"];
|
||||
// Is delete the best way to do this??
|
||||
// Remove CORS headers
|
||||
delete headers["access-control-allow-origin"];
|
||||
delete headers["access-control-allow-credentials"];
|
||||
delete headers["access-control-allow-headers"];
|
||||
delete headers["access-control-allow-methods"];
|
||||
|
||||
// Cloudflare headers
|
||||
delete headers["server"];
|
||||
delete headers["nel"];
|
||||
delete headers["report-to"];
|
||||
delete headers["cf-cache-status"];
|
||||
delete headers["cf-ray"];
|
||||
delete headers["alt-svc"];
|
||||
// Cloudflare headers
|
||||
delete headers["server"];
|
||||
delete headers["nel"];
|
||||
delete headers["report-to"];
|
||||
delete headers["cf-cache-status"];
|
||||
delete headers["cf-ray"];
|
||||
delete headers["alt-svc"];
|
||||
|
||||
// Misc headers
|
||||
delete headers["transfer-encoding"];
|
||||
// Misc headers
|
||||
delete headers["transfer-encoding"];
|
||||
|
||||
// Add node specific headers
|
||||
headers["x-proxy-node"] = process.env.NODE_ID;
|
||||
headers["x-proxy-response-time"] = Date.now() - before + "ms";
|
||||
// Add node specific headers
|
||||
headers["x-proxy-node"] = process.env.NODE_ID;
|
||||
headers["x-proxy-response-time"] = Date.now() - before + "ms";
|
||||
|
||||
// Return the JSON response
|
||||
res.status(response.status).set(headers).json(data);
|
||||
// Return the JSON response
|
||||
res.status(response.status).set(headers).json(data);
|
||||
} catch (ex) {
|
||||
res
|
||||
.status(500)
|
||||
.json(RouteMessages.internalServerError("Error fetching URL"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user