Browse Source

add support for trustedProxy `GATEWAY` to determine automatically from gateway. That's useful in docker where an nginx on the host is not always on a known ip.

master 1.7.3
Gisle Aune 3 years ago
parent
commit
2486c98da7
  1. 9
      server.js

9
server.js

@ -28,7 +28,12 @@ lasso.configure(require("./marko-config"))
// Set trusted proxy
if (config.trustedProxy != null) {
if (ip.isV4Format(config.trustedProxy) || ip.isV6Format(config.trustedProxy)) {
if (config.trustedProxy === "GATEWAY") {
const ip = require("child_process").execSync("/sbin/ip route|awk '/default/ { print $3 }'").toString().trim()
app.set('trust proxy', ip)
console.log("Trusting proxy from default gateway", ip);
} else if (ip.isV4Format(config.trustedProxy) || ip.isV6Format(config.trustedProxy)) {
app.set('trust proxy', config.trustedProxy)
console.log("Trusting proxy", config.trustedProxy);
@ -128,4 +133,4 @@ app.listen(config.port, function() {
// Handle shutdown signals (Docker needs this to shutdown quickly)
process.on('SIGINT', () => process.exit(0))
process.on('SIGTERM', () => process.exit(0))
process.on('SIGTERM', () => process.exit(0))
Loading…
Cancel
Save