mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
feature(config) add
This commit is contained in:
parent
7d93c9930c
commit
cd296f84be
5 changed files with 81 additions and 115 deletions
|
|
@ -1,17 +1,7 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
if (!global.cloudcmd)
|
||||
return console.log(
|
||||
'# server.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,
|
||||
|
||||
DIR = __dirname + '/../',
|
||||
var DIR = __dirname + '/../',
|
||||
DIR_LIB = DIR + 'lib/',
|
||||
DIR_SERVER = DIR_LIB + 'server/',
|
||||
|
||||
|
|
@ -31,6 +21,8 @@
|
|||
rest = require(DIR_SERVER + 'rest'),
|
||||
route = require(DIR_SERVER + 'route'),
|
||||
|
||||
config = require(DIR_SERVER + 'config'),
|
||||
|
||||
join = require(DIR_SERVER + 'join'),
|
||||
ponse = require(DIR_SERVER + 'ponse'),
|
||||
express = require(DIR_SERVER + 'express'),
|
||||
|
|
@ -58,35 +50,31 @@
|
|||
*/
|
||||
module.exports = function() {
|
||||
var port, ip,
|
||||
HTTP = 'http://',
|
||||
config = main.config;
|
||||
HTTP = 'http://';
|
||||
|
||||
port = process.env.PORT || /* c9 */
|
||||
process.env.VCAP_APP_PORT || /* cloudfoundry */
|
||||
config.port,
|
||||
config('port'),
|
||||
|
||||
ip = process.env.IP || /* c9 */
|
||||
config.ip ||
|
||||
config('ip') ||
|
||||
'0.0.0.0';
|
||||
|
||||
if (config.server)
|
||||
if (config('server'))
|
||||
createServer(port, ip, HTTP);
|
||||
};
|
||||
|
||||
function createServer(port, ip, protocol, callback) {
|
||||
var server, app, respondApp,
|
||||
config = main.config,
|
||||
|
||||
middle = controller.middle(DIR),
|
||||
|
||||
isOption = function(name) {
|
||||
return function() {
|
||||
return main.config[name];
|
||||
};
|
||||
return config(name);
|
||||
},
|
||||
|
||||
isMinify = isOption('minify'),
|
||||
isOnline = isOption('online'),
|
||||
isMinify = isOption.bind(null, 'minify'),
|
||||
isOnline = isOption.bind(null, 'online'),
|
||||
|
||||
funcs = [
|
||||
rest,
|
||||
|
|
@ -140,10 +128,9 @@
|
|||
|
||||
function addSockets(server) {
|
||||
var socket, msg,
|
||||
config = main.config,
|
||||
status = 'off';
|
||||
|
||||
if (config.socket && io) {
|
||||
if (io && config('socket')) {
|
||||
socket = io.listen(server);
|
||||
|
||||
if (socket) {
|
||||
|
|
@ -177,8 +164,7 @@
|
|||
* @param res - ответ сервера (Response)
|
||||
*/
|
||||
function controller(dir, req, res) {
|
||||
var config = main.config,
|
||||
parsedUrl = URL.parse(req.url),
|
||||
var parsedUrl = URL.parse(req.url),
|
||||
query = parsedUrl.search || '',
|
||||
name = ponse.getPathName(req);
|
||||
|
||||
|
|
@ -189,7 +175,7 @@
|
|||
|
||||
ponse.sendFile({
|
||||
name : name,
|
||||
cache : config.cache,
|
||||
cache : config('cache'),
|
||||
gzip : true,
|
||||
request : req,
|
||||
response : res
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue