add-basic-auth
Advanced tools
Comparing version 1.1.2 to 1.1.3
56
index.js
@@ -16,3 +16,3 @@ #!/usr/bin/env node | ||
const unauthorized = res => { | ||
const unauthorized = (res) => { | ||
res.writeHead(401, null, { 'WWW-Authenticate': 'Basic' }); | ||
@@ -27,31 +27,35 @@ res.end(); | ||
http | ||
.createServer((req, res) => { | ||
const creds = auth(req); | ||
const proxyServer = http.createServer((req, res) => { | ||
const creds = auth(req); | ||
if (!creds) { | ||
return unauthorized(res); | ||
} | ||
if (!creds) { | ||
return unauthorized(res); | ||
} | ||
const { name, pass } = creds; | ||
const { name, pass } = creds; | ||
if (name !== argv.username || pass !== argv.password) { | ||
console.warn( | ||
`Incorrect username and password from ${req.socket.remoteAddress}` | ||
); | ||
return unauthorized(res); | ||
if (name !== argv.username || pass !== argv.password) { | ||
console.warn( | ||
`Incorrect username and password from ${req.socket.remoteAddress}` | ||
); | ||
return unauthorized(res); | ||
} | ||
proxy.web(req, res, null, (error) => { | ||
if (error) { | ||
console.warn(`Upstream error: ${error.message}`); | ||
res.writeHead(502); | ||
res.end(); | ||
} | ||
}); | ||
}); | ||
proxy.web(req, res, null, error => { | ||
if (error) { | ||
console.warn(`Upstream error: ${error.message}`); | ||
res.writeHead(502); | ||
res.end(); | ||
} | ||
}); | ||
}) | ||
.listen(argv.listenPort, () => { | ||
console.log( | ||
`Proxying with basic auth from port ${argv.listenPort} to ${argv.target}` | ||
); | ||
}); | ||
proxyServer.on('upgrade', function (req, socket, head) { | ||
proxy.ws(req, socket, head); | ||
}); | ||
proxyServer.listen(argv.listenPort, () => { | ||
console.log( | ||
`Proxying with basic auth from port ${argv.listenPort} to ${argv.target}` | ||
); | ||
}); |
{ | ||
"name": "add-basic-auth", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Protect a resource with basic auth", | ||
@@ -26,6 +26,6 @@ "bin": { | ||
"dependencies": { | ||
"basic-auth": "2.0.0", | ||
"http-proxy": "1.16.2", | ||
"yargs": "11.0.0" | ||
"basic-auth": "~2.0.1", | ||
"http-proxy": "~1.18.1", | ||
"yargs": "~17.7.2" | ||
} | ||
} |
4021
49
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedbasic-auth@2.0.1(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedeventemitter3@4.0.7(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedhttp-proxy@1.18.1(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)
- Removedansi-regex@2.1.13.0.1(transitive)
- Removedbasic-auth@2.0.0(transitive)
- Removedcamelcase@4.1.0(transitive)
- Removedcliui@4.1.0(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedcross-spawn@5.1.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removedeventemitter3@1.2.0(transitive)
- Removedexeca@0.7.0(transitive)
- Removedfind-up@2.1.0(transitive)
- Removedget-caller-file@1.0.3(transitive)
- Removedget-stream@3.0.0(transitive)
- Removedhttp-proxy@1.16.2(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-fullwidth-code-point@1.0.02.0.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedlcid@1.0.0(transitive)
- Removedlocate-path@2.0.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedmem@1.1.0(transitive)
- Removedmimic-fn@1.2.0(transitive)
- Removednpm-run-path@2.0.2(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedos-locale@2.1.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-limit@1.3.0(transitive)
- Removedp-locate@2.0.0(transitive)
- Removedp-try@1.0.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedpath-key@2.0.1(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedrequire-main-filename@1.0.1(transitive)
- Removedsafe-buffer@5.1.1(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedshebang-command@1.2.0(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstring-width@1.0.22.1.1(transitive)
- Removedstrip-ansi@3.0.14.0.0(transitive)
- Removedstrip-eof@1.0.0(transitive)
- Removedwhich@1.3.1(transitive)
- Removedwhich-module@2.0.1(transitive)
- Removedwrap-ansi@2.1.0(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyallist@2.1.2(transitive)
- Removedyargs@11.0.0(transitive)
- Removedyargs-parser@9.0.2(transitive)
Updatedbasic-auth@~2.0.1
Updatedhttp-proxy@~1.18.1
Updatedyargs@~17.7.2