Use experimental DNS resolution on redirects

This change disables axios' built-in redirect handling and instead handles redirects manually. This ensures that the experimental DNS resolution works on redirects too, and not just on the initial request.
This commit is contained in:
Paul Bütof 2025-12-02 18:38:05 +01:00
parent 2985f279c6
commit bcfcc74531
No known key found for this signature in database
GPG key ID: E361872980357C54

View file

@ -128,6 +128,23 @@ class Server {
}
return config
})
// Manually handle redirects, otherwise axios would bypass custom dns resolution on redirects
axios.defaults.maxRedirects = 0
axios.interceptors.response.use(
(response) => response,
async (error) => {
if (error.response && [301, 302, 303, 307, 308].includes(error.response.status) && error.response.headers.location) {
const redirectUrl = error.response.headers.location
Logger.debug(`[Server] Following ${error.response.status} redirect to ${redirectUrl}`)
return axios({
...error.config,
url: redirectUrl
})
}
return Promise.reject(error)
}
)
}
global.PodcastDownloadTimeout = toNumber(process.env.PODCAST_DOWNLOAD_TIMEOUT, 30000)