feature(express) rm main

This commit is contained in:
coderaiser 2014-08-21 11:43:23 -04:00
parent 8894bca353
commit 5637174389
2 changed files with 30 additions and 13 deletions

View file

@ -119,6 +119,7 @@
function createServer(port, ip, protocol, ssl, callback) {
var server, app, respondApp,
config = main.config,
isMinify = function() {
var isMinify = main.config.minify;
@ -138,7 +139,11 @@
})
];
expressApp = express.getApp(funcs);
expressApp = express.getApp(funcs, {
auth : config.auth,
username: config.username,
password: config.password
});
if (expressApp) {
app = expressApp;

View file

@ -2,30 +2,33 @@
'use strict';
var DIR = __dirname + '/../../',
DIR_LIB = DIR + 'lib/',
Util = require(DIR_LIB + 'util'),
crypto = require('crypto'),
main = global.cloudcmd.main,
express = main.require('express'),
httpAuth = main.require('http-auth'),
logger = main.require('morgan'),
Util = main.util,
express = tryRequire('express'),
httpAuth = tryRequire('http-auth'),
logger = tryRequire('morgan'),
basic,
oldPass,
oldName,
app = express && express();
exports.getApp = function(middleware) {
var isArray = Util.isArray(middleware),
config = main.config,
auth = config.auth;
exports.getApp = function(middleware, config) {
var isArray = Util.isArray(middleware);
if (!config)
config.auth = false;
if (app) {
if (logger)
app.use(logger('dev'));
if (auth && httpAuth) {
initAuth();
if (config.auth && httpAuth) {
initAuth(config);
app.use(httpAuth.connect(basic));
}
@ -41,12 +44,11 @@
};
function initAuth() {
function initAuth(config) {
basic = httpAuth.basic({
realm: 'Cloud Commander'
}, function (username, password, callback) { // Custom authentication method.
var hash,
config = main.config,
name = config.username,
passwd = config.password,
equal = username === name,
@ -75,4 +77,14 @@
callback(equal);
});
}
function tryRequire(name) {
var module;
Util.exec.try(function() {
module = require(name);
});
return module;
}
})();