mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(express) rm main
This commit is contained in:
parent
8894bca353
commit
5637174389
2 changed files with 30 additions and 13 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue