1
1
const
2
- bodyParser = require ( 'body-parser' ) ;
3
- fs = require ( 'fs' ) ,
2
+ bodyParser = require ( 'body-parser' ) ;
3
+ fs = require ( 'fs' ) ,
4
4
path = require ( 'path' ) ,
5
5
spawn = require ( 'child_process' ) . spawn ,
6
6
express = require ( 'express' ) ,
7
7
pod = require ( '../lib/api' ) ,
8
8
ghURL = require ( 'parse-github-url' ) ,
9
9
app = express ( ) ,
10
- // favicon = require('serve-favicon'),
10
+ // favicon = require('serve-favicon'),
11
11
statics = require ( 'serve-static' ) ,
12
12
basicAuth = require ( 'basic-auth' ) ;
13
13
@@ -19,21 +19,17 @@ var reloadConf = function (req, res, next) {
19
19
conf = pod . reloadConfig ( )
20
20
next ( )
21
21
}
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 ( ) ;
32
32
} ;
33
- var aauth = ( ) => {
34
- return auth ( ( conf . web . username || 'admin' ) , ( conf . web . password || 'admin' ) ) ;
35
- }
36
-
37
33
38
34
app . set ( 'views' , __dirname + '/views' )
39
35
app . set ( 'view engine' , 'ejs' )
@@ -43,19 +39,20 @@ app.use(bodyParser.json())
43
39
app . use ( statics ( path . join ( __dirname , 'static' ) ) )
44
40
45
41
46
- app . get ( '/' , aauth , function ( req , res ) {
42
+ app . get ( '/' , auth , function ( req , res ) {
47
43
pod . listApps ( function ( err , list ) {
48
44
if ( err ) return res . end ( err )
49
- res . render ( 'index' , {
45
+ return res . render ( 'index' , {
50
46
apps : list
51
47
} )
52
48
} )
53
49
} )
54
50
55
- app . get ( '/json' , aauth , function ( req , res ) {
51
+ app . get ( '/json' , auth , function ( req , res ) {
56
52
pod . listApps ( function ( err , list ) {
57
53
if ( err ) return res . end ( err )
58
54
res . json ( list )
55
+ res . end ( ) ;
59
56
} )
60
57
} )
61
58
@@ -202,4 +199,4 @@ function executeHook(appid, app, payload, cb) {
202
199
} )
203
200
} )
204
201
}
205
-
202
+
0 commit comments