From 8894bca3538068e4d5344d6f759c58c02106b566 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 21 Aug 2014 11:34:09 -0400 Subject: [PATCH] feature(express) add static --- lib/server.js | 36 ++++++++++++++++++------------------ lib/server/express.js | 17 +++++++---------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/lib/server.js b/lib/server.js index 1cdd6bc2..350aefe1 100644 --- a/lib/server.js +++ b/lib/server.js @@ -118,36 +118,36 @@ } function createServer(port, ip, protocol, ssl, callback) { - var server, app, + var server, app, respondApp, + isMinify = function() { + var isMinify = main.config.minify; + + return isMinify; + }, funcs = [ Rest, Route, join({ - minify: function() { - var isMinify = main.config.minify; - - return isMinify; - } + minify: isMinify }), minify({ dir : DIR, log : true, - is : function() { - var isMinify = main.config.minify; - - return isMinify; - } - }), - - controller.middle(DIR) - ], + is : isMinify + }) + ]; - respondApp = Util.exec.with(respond, funcs); - expressApp = express.getApp(funcs); - app = expressApp || respondApp; + if (expressApp) { + app = expressApp; + } else { + funcs.push(controller.middle(DIR)); + + respondApp = Util.exec.with(respond, funcs); + app = respondApp; + } if (ssl) server = https.createServer(ssl, app); diff --git a/lib/server/express.js b/lib/server/express.js index 9da77f08..f0d36f10 100644 --- a/lib/server/express.js +++ b/lib/server/express.js @@ -1,20 +1,15 @@ (function() { 'use strict'; - if (!global.cloudcmd) - return console.log( - '# express.js' + '\n' + - '# -----------' + '\n' + - '# Module is part of Cloud Commander,' + '\n' + - '# easy to use web server.' + '\n' + - '# http://cloudcmd.io' + '\n'); - - var main = global.cloudcmd.main, + var DIR = __dirname + '/../../', + + crypto = require('crypto'), + main = global.cloudcmd.main, express = main.require('express'), httpAuth = main.require('http-auth'), logger = main.require('morgan'), Util = main.util, - crypto = require('crypto'), + basic, oldPass, oldName, @@ -38,6 +33,8 @@ middleware.forEach(function(middle) { app.use(middle); }); + + app.use(express.static(DIR)); } return app;