Browse Source

server: Added DNS resolution when setting trust proxy since IPs are temporary in Docker.

1.2
Gisle Aune 6 years ago
parent
commit
c0e74f4756
  1. 5
      package-lock.json
  2. 1
      package.json
  3. 23
      server.js

5
package-lock.json

@ -3405,6 +3405,11 @@
"loose-envify": "^1.0.0"
}
},
"ip": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
},
"ipaddr.js": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz",

1
package.json

@ -26,6 +26,7 @@
"express-session": "^1.15.6",
"graphql-query-compress": "^1.1.0",
"http-proxy-middleware": "^0.19.1",
"ip": "^1.1.5",
"isomorphic-fetch": "^2.2.1",
"jsonwebtoken": "^8.3.0",
"lasso": "^3.2.6",

23
server.js

@ -9,6 +9,8 @@ const config = require("./config")
const express = require("express")
const proxy = require("express-http-proxy")
const proxy2 = require("http-proxy-middleware")
const ip = require("ip")
const dns = require("dns")
const lasso = require("lasso")
const lassoMiddleware = require("lasso/middleware")
const markoExpress = require("marko/express")
@ -26,7 +28,26 @@ lasso.configure(require("./marko-config"))
// Set trusted proxy
if (config.trustedProxy != null) {
app.set('trust proxy', config.trustedProxy)
if (ip.isV4Format(config.trustedProxy) || ip.isV6Format(config.trustedProxy)) {
app.set('trust proxy', config.trustedProxy)
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)
}
console.log("Trusting proxy", res[0], `(${config.trustedProxy})`);
app.set('trust proxy', res[0])
})
}
}
// Apply middleware

Loading…
Cancel
Save