|
|
@ -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) { |
|
|
|
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
|
|
|
|