Skip to content

Commit ec90b8f

Browse files
authored
Use basic-auth in express 4
1 parent 492a102 commit ec90b8f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

web/app.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const
88
ghURL = require('parse-github-url'),
99
app = express(),
1010
favicon = require('serve-favicon'),
11-
statics = require('serve-static')
11+
statics = require('serve-static'),
12+
basicAuth = require('basic-auth');
1213

1314
// late def, wait until pod is ready
1415
var conf
@@ -19,10 +20,15 @@ var reloadConf = function (req, res, next) {
1920
next()
2021
}
2122

22-
var auth = express.basicAuth(function (user, pass) {
23+
var auth = basicAuth(function (user, pass) {
2324
var u = conf.web.username || 'admin',
2425
p = conf.web.password || 'admin'
25-
return user === u && pass === p
26+
if(!( user === u && pass === p ))
27+
{
28+
res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
29+
return res.send(401);
30+
}
31+
next();
2632
})
2733

2834
app.configure(function () {
@@ -194,3 +200,4 @@ function executeHook(appid, app, payload, cb) {
194200
})
195201
})
196202
}
203+

0 commit comments

Comments
 (0)