Skip to content

Commit

Permalink
nvm just redirect it
Browse files Browse the repository at this point in the history
  • Loading branch information
InventivetalentDev committed Dec 3, 2024
1 parent a72e2f7 commit 49b39cb
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions routes/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,17 @@ module.exports = function (express, config) {
proxyUrlDownload(req, res, url);
}

const PROXY_REDIRECT_WHITELIST = [
'https://www.spigotmc.org/resources/',
'https://github.com/',
'https://objects.githubusercontent.com/'
]

function proxyUrlDownload(req, res, url, r = 4) {
console.log("proxying download for " + url)
https.get(url, {
headers: {
'User-Agent': config.userAgent
}
}, resp => {
if (r > 0 && (resp.statusCode === 301 || resp.statusCode === 302 || resp.statusCode === 307) && PROXY_REDIRECT_WHITELIST.some(w => resp.headers.location.startsWith(w))) {
res.set('X-Spiget-Redirect-' + r, resp.headers.location);
if (resp.statusCode === 301 || resp.statusCode === 302 || resp.statusCode === 307) {
console.log("redirecting to " + resp.headers.location);
proxyUrlDownload(req, res, resp.headers.location, r - 1);
res.set('Location', resp.headers.location);
res.status(307).end();
return;
}
console.log(resp.statusCode + " " + url);
Expand Down

0 comments on commit 49b39cb

Please sign in to comment.