Skip to content

Commit

Permalink
feat: added PROXY protocol support per <ladjs/lad#400>
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Jul 6, 2020
1 parent ab732d5 commit d2a4102
Show file tree
Hide file tree
Showing 3 changed files with 2,456 additions and 2,877 deletions.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const Router = require('router');
const _ = require('lodash');
const finalhandler = require('finalhandler');
const parse = require('url-parse');
const proxyWrap = require('findhit-proxywrap');
const { boolean } = require('boolean');

const proxiedHttp = proxyWrap.proxy(http);

class ProxyServer {
constructor(config) {
Expand All @@ -15,6 +19,7 @@ class ProxyServer {
name: process.env.CERTBOT_WELL_KNOWN_NAME || null,
contents: process.env.CERTBOT_WELL_KNOWN_CONTENTS || null
},
proxyProtocol: boolean(process.env.PROXY_PROTOCOL || false),
removeWwwPrefix: true,
// useful option if you don't need https redirect
// (e.g. it's just a certbot server)
Expand Down Expand Up @@ -52,7 +57,11 @@ class ProxyServer {
res.end();
});

this.server = http.createServer((req, res) => {
const createServer = this.config.proxyProtocol
? proxiedHttp.createServer
: http.createServer;

this.server = createServer((req, res) => {
router(req, res, finalhandler(req, res));
});

Expand Down
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,27 @@
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)"
],
"dependencies": {
"boolean": "^3.0.1",
"finalhandler": "^1.1.2",
"findhit-proxywrap": "^0.3.12",
"lodash": "^4.17.15",
"router": "^1.3.3",
"router": "^1.3.5",
"url-parse": "^1.4.7"
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"ava": "^2.4.0",
"codecov": "^3.6.1",
"cross-env": "^6.0.3",
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"ava": "^3.10.0",
"codecov": "^3.7.0",
"cross-env": "^7.0.2",
"eslint": "^6.7.2",
"eslint-config-xo-lass": "^1.0.3",
"fixpack": "^2.3.1",
"husky": "^3.1.0",
"lint-staged": "^9.5.0",
"nyc": "^14.1.1",
"remark-cli": "^7.0.1",
"remark-preset-github": "^0.0.16",
"fixpack": "^3.0.6",
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"nyc": "^15.1.0",
"remark-cli": "^8.0.0",
"remark-preset-github": "^2.0.2",
"supertest": "^4.0.2",
"xo": "^0.25.3"
},
Expand Down
Loading

0 comments on commit d2a4102

Please sign in to comment.