server: Added resilience to trust proxy resolution to handle IP changes and bad start order.
This commit is contained in:
@@ -33,20 +33,33 @@ if (config.trustedProxy != null) {
|
||||
|
||||
console.log("Trusting proxy", config.trustedProxy);
|
||||
} else {
|
||||
dns.resolve4(config.trustedProxy, (err, res) => {
|
||||
if (err != null) {
|
||||
console.error("Failed to resolve trustedProxy hostname")
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
}
|
||||
if (res.length === 0) {
|
||||
console.error("No results for trustedProxy hostname")
|
||||
process.exit(1)
|
||||
}
|
||||
let trusted = null
|
||||
|
||||
console.log("Trusting proxy", res[0], `(${config.trustedProxy})`);
|
||||
app.set('trust proxy', res[0])
|
||||
})
|
||||
setInterval(() => {
|
||||
dns.resolve4(config.trustedProxy, (err, res) => {
|
||||
if (err != null) {
|
||||
if (trusted === null) {
|
||||
console.error("Failed to resolve trustedProxy hostname")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
if (res.length === 0) {
|
||||
if (trusted === null) {
|
||||
console.error("No results for trustedProxy hostname")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (trusted !== res[0]) {
|
||||
console.log("Trusting proxy", res[0], `(${config.trustedProxy})`);
|
||||
app.set('trust proxy', res[0])
|
||||
|
||||
trusted = res[0]
|
||||
}
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user