Skip to content

Commit 1dc00f4

Browse files
committed
fix basic auth
1 parent dbc8ce3 commit 1dc00f4

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

web/app.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const
2-
bodyParser = require('body-parser');
3-
fs = require('fs'),
2+
bodyParser = require('body-parser');
3+
fs = require('fs'),
44
path = require('path'),
55
spawn = require('child_process').spawn,
66
express = require('express'),
77
pod = require('../lib/api'),
88
ghURL = require('parse-github-url'),
99
app = express(),
10-
// favicon = require('serve-favicon'),
10+
// favicon = require('serve-favicon'),
1111
statics = require('serve-static'),
1212
basicAuth = require('basic-auth');
1313

@@ -19,21 +19,17 @@ var reloadConf = function (req, res, next) {
1919
conf = pod.reloadConfig()
2020
next()
2121
}
22-
var auth = function(username, password) {
23-
return function(req, res, next) {
24-
var user = basicAuth(req);
25-
if (!user || user.name !== username || user.pass !== password)
26-
{
27-
res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
28-
return res.send(401);
29-
}
30-
next();
31-
};
22+
var auth = function (req, res, next) {
23+
var user = basicAuth(req);
24+
const username = (conf.web.username || 'admin');
25+
const password = (conf.web.password || 'admin');
26+
console.log(JSON.stringify(user))
27+
if (!user || user.name !== username || user.pass !== password) {
28+
res.setHeader('WWW-Authenticate', 'Basic realm=Authorization Required');
29+
return res.sendStatus(401);
30+
}
31+
next();
3232
};
33-
var aauth = ()=>{
34-
return auth((conf.web.username || 'admin'),(conf.web.password || 'admin'));
35-
}
36-
3733

3834
app.set('views', __dirname + '/views')
3935
app.set('view engine', 'ejs')
@@ -43,19 +39,20 @@ app.use(bodyParser.json())
4339
app.use(statics(path.join(__dirname, 'static')))
4440

4541

46-
app.get('/', aauth, function (req, res) {
42+
app.get('/', auth, function (req, res) {
4743
pod.listApps(function (err, list) {
4844
if (err) return res.end(err)
49-
res.render('index', {
45+
return res.render('index', {
5046
apps: list
5147
})
5248
})
5349
})
5450

55-
app.get('/json', aauth, function (req, res) {
51+
app.get('/json', auth, function (req, res) {
5652
pod.listApps(function (err, list) {
5753
if (err) return res.end(err)
5854
res.json(list)
55+
res.end();
5956
})
6057
})
6158

@@ -202,4 +199,4 @@ function executeHook(appid, app, payload, cb) {
202199
})
203200
})
204201
}
205-
202+

0 commit comments

Comments
 (0)