Skip to content

Commit

Permalink
fix: fixed linting
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Jul 20, 2020
1 parent 0e350d6 commit 72a6ecd
Show file tree
Hide file tree
Showing 5 changed files with 1,208 additions and 953 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- '8'
- '10'
- '12'
after_success:
npm run coverage
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,32 @@ class ProxyServer {
)
router.get(
`/.well-known/acme-challenge/${this.config.certbot.name}`,
(req, res) => {
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
res.end(this.config.certbot.contents);
(request, response) => {
response.setHeader('Content-Type', 'text/plain; charset=utf-8');
response.end(this.config.certbot.contents);
}
);

if (this.config.redirect)
router.use((req, res) => {
router.use((request, response) => {
if (this.config.removeWwwPrefix)
req.headers.host = req.headers.host.replace('www.', '');
res.writeHead(301, {
Location: parse(`https://${req.headers.host}${req.url}`).href
request.headers.host = request.headers.host.replace('www.', '');
response.writeHead(301, {
Location: parse(`https://${request.headers.host}${request.url}`).href
});
res.end();
response.end();
});
else
router.use((req, res) => {
res.end();
router.use((request, response) => {
response.end();
});

const createServer = this.config.proxyProtocol
? proxiedHttp.createServer
: http.createServer;

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

// bind listen/close to this
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@
"boolean": "^3.0.1",
"finalhandler": "^1.1.2",
"findhit-proxywrap": "^0.3.12",
"lodash": "^4.17.15",
"lodash": "^4.17.19",
"router": "^1.3.5",
"url-parse": "^1.4.7"
},
"devDependencies": {
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"ava": "^3.10.0",
"codecov": "^3.7.0",
"@commitlint/cli": "^9.1.1",
"@commitlint/config-conventional": "^9.1.1",
"ava": "^3.10.1",
"codecov": "^3.7.1",
"cross-env": "^7.0.2",
"eslint": "^6.7.2",
"eslint": "^7.5.0",
"eslint-config-xo-lass": "^1.0.3",
"fixpack": "^3.0.6",
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"nyc": "^15.1.0",
"remark-cli": "^8.0.0",
"remark-cli": "^8.0.1",
"remark-preset-github": "^2.0.2",
"sinon": "^9.0.2",
"supertest": "^4.0.2",
"xo": "^0.25.3"
"xo": "^0.32.1"
},
"engines": {
"node": ">=8.3"
Expand Down
36 changes: 18 additions & 18 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,55 @@ const request = require('supertest');

const ProxyServer = require('..');

test('starts and stops server', async t => {
test('starts and stops server', async (t) => {
const proxy = new ProxyServer();
await proxy.listen();
await proxy.close();
t.pass();
});

test('redirects http to https', async t => {
test('redirects http to https', async (t) => {
const proxy = new ProxyServer();
await proxy.listen();
const res = await request(proxy.server).get('/foobar');
const response = await request(proxy.server).get('/foobar');
const { port } = proxy.server.address();
t.is(res.status, 301);
t.is(res.headers.location, `https://127.0.0.1:${port}/foobar`);
t.is(response.status, 301);
t.is(response.headers.location, `https://127.0.0.1:${port}/foobar`);
});

test('does not redirect http to https', async t => {
test('does not redirect http to https', async (t) => {
const proxy = new ProxyServer({ redirect: false });
await proxy.listen();
const res = await request(proxy.server).get('/foobar');
t.is(res.status, 200);
const response = await request(proxy.server).get('/foobar');
t.is(response.status, 200);
});

test('serves acme challenge', async t => {
test('serves acme challenge', async (t) => {
const config = {
certbot: {
name: 'name',
contents: 'contents'
}
};
const proxy = new ProxyServer(config);
const res = await request(proxy.server).get(
const response = await request(proxy.server).get(
`/.well-known/acme-challenge/${config.certbot.name}`
);
t.is(res.status, 200);
t.is(res.headers['content-type'], 'text/plain; charset=utf-8');
t.is(res.text, config.certbot.contents);
t.is(response.status, 200);
t.is(response.headers['content-type'], 'text/plain; charset=utf-8');
t.is(response.text, config.certbot.contents);
});

test('redirects http to https and does not remove prefix', async t => {
test('redirects http to https and does not remove prefix', async (t) => {
const proxy = new ProxyServer({ removeWwwPrefix: false });
await proxy.listen();
const res = await request(proxy.server).get('/foobar');
const response = await request(proxy.server).get('/foobar');
const { port } = proxy.server.address();
t.is(res.status, 301);
t.is(res.headers.location, `https://127.0.0.1:${port}/foobar`);
t.is(response.status, 301);
t.is(response.headers.location, `https://127.0.0.1:${port}/foobar`);
});

test('starts and stops server with proxyProtocol = true', async t => {
test('starts and stops server with proxyProtocol = true', async (t) => {
const proxy = new ProxyServer({ proxyProtocol: true });
await proxy.listen();
await proxy.close();
Expand Down
Loading

0 comments on commit 72a6ecd

Please sign in to comment.