mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
index processing function moved out from server.js to cloudcmd.js
This commit is contained in:
parent
26d3f04454
commit
16e1fe33bd
2 changed files with 55 additions and 44 deletions
54
cloudcmd.js
54
cloudcmd.js
|
|
@ -1,21 +1,59 @@
|
|||
"use strict";
|
||||
|
||||
var DIR = process.cwd() + '/',
|
||||
SRVDIR = DIR + 'lib/server/',
|
||||
var DIR = process.cwd() + '/',
|
||||
LIBDIR = DIR + 'lib/',
|
||||
SRVDIR = LIBDIR + 'server/',
|
||||
|
||||
srvfunc = require(SRVDIR + 'srvfunc'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
Server = srvfunc.require(DIR + 'server'),
|
||||
update = srvfunc.require(SRVDIR + 'update'),
|
||||
srvfunc = require(SRVDIR + 'srvfunc'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
Server = srvfunc.require(DIR + 'server'),
|
||||
CloudFunc = srvfunc.require(LIBDIR +'cloudfunc'),
|
||||
update = srvfunc.require(SRVDIR + 'update'),
|
||||
|
||||
Config = readConfig();
|
||||
|
||||
Server.start(Config);
|
||||
Server.start(Config, indexProcessing);
|
||||
|
||||
if(update)
|
||||
update.get();
|
||||
|
||||
function indexProcessing(pIndex, pList){
|
||||
var lWin32 = process.platform === 'win32';
|
||||
|
||||
/* если выбрана опция минифизировать скрпиты
|
||||
* меняем в index.html обычные css на
|
||||
* минифицированый
|
||||
*/
|
||||
if(Server.CloudServer.Minify._allowed.css){
|
||||
var lReplace_s = '<link rel=stylesheet href=';
|
||||
if(lWin32)
|
||||
lReplace_s = lReplace_s + '/css/reset.css>';
|
||||
else
|
||||
lReplace_s = lReplace_s + '"/css/reset.css">';
|
||||
|
||||
pIndex = pIndex.replace(lReplace_s, '');
|
||||
pIndex = pIndex.replace('/css/style.css', Server.CloudServer.Minify.MinFolder + 'all.min.css');
|
||||
}
|
||||
|
||||
pIndex = pIndex.replace('<div id=fm class=no-js>',
|
||||
'<div id=fm class=no-js>'+ pList);
|
||||
|
||||
/* меняем title */
|
||||
pIndex = pIndex.replace('<title>Cloud Commander</title>',
|
||||
'<title>' + CloudFunc.setTitle() + '</title>');
|
||||
|
||||
if(!Server.CloudServer.Config.appcache){
|
||||
if(lWin32)
|
||||
pIndex = pIndex.replace(' manifest=/cloudcmd.appcache', '');
|
||||
else
|
||||
pIndex = pIndex.replace(' manifest="/cloudcmd.appcache"', '');
|
||||
}
|
||||
|
||||
return pIndex;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function readConfig(){
|
||||
|
||||
|
|
|
|||
45
server.js
45
server.js
|
|
@ -155,14 +155,16 @@ CloudServer.init = (function(){
|
|||
* Функция создаёт сервер
|
||||
* @param pConfig
|
||||
*/
|
||||
CloudServer.start = function (pConfig) {
|
||||
CloudServer.start = function (pConfig, pIndexProcessing) {
|
||||
if(pConfig)
|
||||
this.Config = pConfig;
|
||||
else
|
||||
console.log('warning: configuretion file config.json not found...\n' +
|
||||
'using default values...\n' +
|
||||
JSON.stringify(this.Config));
|
||||
|
||||
|
||||
CloudServer.indexProcessing = pIndexProcessing;
|
||||
|
||||
this.init();
|
||||
|
||||
this.Port = process.env.PORT || /* c9 */
|
||||
|
|
@ -675,37 +677,7 @@ CloudServer.indexReaded = function(pList){
|
|||
|
||||
pIndex = pIndex.toString();
|
||||
|
||||
var lWin32 = process.platform === 'win32';
|
||||
|
||||
/* если выбрана опция минифизировать скрпиты
|
||||
* меняем в index.html обычные css на
|
||||
* минифицированый
|
||||
*/
|
||||
if(CloudServer.Minify._allowed.css){
|
||||
var lReplace_s = '<link rel=stylesheet href=';
|
||||
if(lWin32)
|
||||
lReplace_s = lReplace_s + '/css/reset.css>';
|
||||
else
|
||||
lReplace_s = lReplace_s + '"/css/reset.css">';
|
||||
|
||||
pIndex = pIndex.replace(lReplace_s, '');
|
||||
pIndex = pIndex.replace('/css/style.css', CloudServer.Minify.MinFolder + 'all.min.css');
|
||||
}
|
||||
|
||||
pIndex = pIndex.toString().replace('<div id=fm class=no-js>',
|
||||
'<div id=fm class=no-js>'+pList);
|
||||
|
||||
/* меняем title */
|
||||
pIndex = pIndex.replace('<title>Cloud Commander</title>',
|
||||
'<title>' + CloudFunc.setTitle() + '</title>');
|
||||
|
||||
if(!CloudServer.Config.appcache){
|
||||
if(lWin32)
|
||||
pIndex = pIndex.replace(' manifest=/cloudcmd.appcache', '');
|
||||
else
|
||||
pIndex = pIndex.replace(' manifest="/cloudcmd.appcache"', '');
|
||||
}
|
||||
|
||||
pIndex = CloudServer.indexProcessing(pIndex, pList);
|
||||
/*
|
||||
* если браузер поддерживает gzip-сжатие
|
||||
* высылаем заголовок в зависимости от типа файла
|
||||
|
|
@ -830,6 +802,7 @@ CloudServer.sendResponse = function(pHead, pData, pName){
|
|||
}
|
||||
};
|
||||
|
||||
exports.start = function(pConfig){
|
||||
CloudServer.start(pConfig);
|
||||
};
|
||||
exports.start = function(pConfig, pIndexProcessing){
|
||||
CloudServer.start(pConfig, pIndexProcessing);
|
||||
};
|
||||
exports.CloudServer = CloudServer;
|
||||
Loading…
Add table
Add a link
Reference in a new issue