diff --git a/lib/app.js b/lib/app.js index 12f8cc77..c1c4e278 100755 --- a/lib/app.js +++ b/lib/app.js @@ -52,7 +52,8 @@ app.use(express.session()); config.load(function(err, conf) { if (err) { console.log(err); process.exit(1); } - atm.init(app, conf.config); + + var authMiddleware = function (req, res, next) { return next(); }; if (argv.http) { http.createServer(app).listen(port, function () { @@ -60,7 +61,7 @@ config.load(function(err, conf) { }); } else { - app.use(clientCertificateAuth({ rejectUnauthorized: false }, function(cert, done) { + authMiddleware = clientCertificateAuth({ rejectUnauthorized: false }, function(cert, done) { config.isAuthorized(cert.fingerprint, function(err, authorized) { if (err) { console.error('Client certificate authorization failed', err.message); @@ -69,7 +70,7 @@ config.load(function(err, conf) { done(authorized); }); - })); + }); var options = { key: fs.readFileSync(argv.key), @@ -84,4 +85,7 @@ config.load(function(err, conf) { console.log('Express server listening on port ' + port + ' (https)'); }); } + + atm.init(app, conf.config, config, authMiddleware); + });