|
@ -9,6 +9,8 @@ const config = require("./config") |
|
|
const express = require("express") |
|
|
const express = require("express") |
|
|
const proxy = require("express-http-proxy") |
|
|
const proxy = require("express-http-proxy") |
|
|
const proxy2 = require("http-proxy-middleware") |
|
|
const proxy2 = require("http-proxy-middleware") |
|
|
|
|
|
const ip = require("ip") |
|
|
|
|
|
const dns = require("dns") |
|
|
const lasso = require("lasso") |
|
|
const lasso = require("lasso") |
|
|
const lassoMiddleware = require("lasso/middleware") |
|
|
const lassoMiddleware = require("lasso/middleware") |
|
|
const markoExpress = require("marko/express") |
|
|
const markoExpress = require("marko/express") |
|
@ -26,7 +28,26 @@ lasso.configure(require("./marko-config")) |
|
|
|
|
|
|
|
|
// Set trusted proxy
|
|
|
// Set trusted proxy
|
|
|
if (config.trustedProxy != null) { |
|
|
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
|
|
|
// Apply middleware
|
|
|