mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
work on rest module
This commit is contained in:
parent
9c98bd901f
commit
876e79eddb
4 changed files with 62 additions and 35 deletions
15
cloudcmd.js
15
cloudcmd.js
|
|
@ -18,7 +18,11 @@
|
|||
Config = main.config;
|
||||
|
||||
readConfig();
|
||||
Server.start(Config, indexProcessing, appCacheProcessing);
|
||||
Server.start(Config, {
|
||||
index : indexProcessing,
|
||||
appcache : appCacheProcessing,
|
||||
rest : rest
|
||||
});
|
||||
|
||||
if(update)
|
||||
update.get();
|
||||
|
|
@ -75,6 +79,15 @@
|
|||
lAppCache.createManifest();
|
||||
}
|
||||
|
||||
/**
|
||||
* rest interface
|
||||
* @pConnectionData {request, responce}
|
||||
*/
|
||||
function rest(pConnectionData){
|
||||
console.log('rest');
|
||||
Util.exec(main.rest, pConnectionData);
|
||||
}
|
||||
|
||||
function readConfig(){
|
||||
|
||||
/* Determining server.js directory
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
exports.http = require('http'),
|
||||
exports.https = require('https'),
|
||||
exports.path = require('path'),
|
||||
exports.url = require('url'),
|
||||
exports.querystring = require('querystring'),
|
||||
|
||||
/* Needed Modules */
|
||||
|
|
|
|||
|
|
@ -4,28 +4,26 @@
|
|||
"use strict";
|
||||
|
||||
var DIR = process.cwd() + '/',
|
||||
main = require(DIR + 'lib/server/main.js'),
|
||||
SRVDIR = main.SRVDIR,
|
||||
main = require(DIR + 'lib/server/main'),
|
||||
Util = main.util,
|
||||
|
||||
APIURL = '/api/v1/';
|
||||
APIURL = '/api/v1/';
|
||||
|
||||
exports.rest = function(req, res, pCallBack){
|
||||
var lUrl = req.url,
|
||||
lMethod = req.method;
|
||||
|
||||
console.log(lUrl);
|
||||
/* if lUrl contains api url */
|
||||
if( Util.isContainStr(lUrl, APIURL) ){
|
||||
lUrl = lUrl.replace(APIURL, '');
|
||||
/**
|
||||
* rest interface
|
||||
* @pConnectionData {request, responce}
|
||||
*/
|
||||
exports.rest = function(pConnectionData){
|
||||
var lReq = pConnectionData.request,
|
||||
lRes = pConnectionData.response,
|
||||
lUrl = lReq.url,
|
||||
lMethod = lReq.method;
|
||||
|
||||
console.log(lUrl);
|
||||
}
|
||||
|
||||
console.log(req.url);
|
||||
console.log(lMethod);
|
||||
|
||||
Util.exec(pCallBack);
|
||||
|
||||
console.log(lMethod);
|
||||
|
||||
if( Util.isContainStr(lUrl, APIURL) )
|
||||
console.log('api !!!!!!!!!!!! ');
|
||||
/*
|
||||
switch(req.method){
|
||||
case 'GET':
|
||||
|
|
|
|||
47
server.js
47
server.js
|
|
@ -140,7 +140,10 @@ CloudServer.init = (function(pAppCachProcessing){
|
|||
* Функция создаёт сервер
|
||||
* @param pConfig
|
||||
*/
|
||||
CloudServer.start = function (pConfig, pIndexProcessing, pAppCachProcessing) {
|
||||
CloudServer.start = function (pConfig, pProcessing) {
|
||||
if(!pProcessing)
|
||||
pProcessing = {};
|
||||
|
||||
if(pConfig)
|
||||
this.Config = pConfig;
|
||||
|
||||
|
|
@ -151,9 +154,10 @@ CloudServer.start = function (pConfig, pIndexProcessing, pAppCachProcessing) {
|
|||
|
||||
var lConfig = this.Config;
|
||||
|
||||
CloudServer.indexProcessing = pIndexProcessing;
|
||||
CloudServer.indexProcessing = pProcessing.index;
|
||||
CloudServer.rest = pProcessing.rest;
|
||||
|
||||
this.init(pAppCachProcessing);
|
||||
this.init(pProcessing.appcache);
|
||||
|
||||
this.Port = process.env.PORT || /* c9 */
|
||||
process.env.app_port || /* nodester */
|
||||
|
|
@ -255,10 +259,11 @@ CloudServer.generateHeaders = function(pName, pGzip){
|
|||
CloudServer._controller = function(pReq, pRes)
|
||||
{
|
||||
/* Читаем содержимое папки, переданное в url */
|
||||
var url = require("url"),
|
||||
lParsedUrl = url.parse(pReq.url),
|
||||
pathname = lParsedUrl.pathname,
|
||||
|
||||
var lConfig = CloudServer.Config,
|
||||
url = main.url,
|
||||
lParsedUrl = url.parse(pReq.url),
|
||||
pathname = lParsedUrl.pathname,
|
||||
|
||||
/* varible contain one of queris:
|
||||
* download - change content-type for
|
||||
* make downloading process
|
||||
|
|
@ -269,7 +274,7 @@ CloudServer._controller = function(pReq, pRes)
|
|||
* query like this
|
||||
* ?json
|
||||
*/
|
||||
lQuery = lParsedUrl.query;
|
||||
lQuery = lParsedUrl.query;
|
||||
if(lQuery)
|
||||
console.log('query = ' + lQuery);
|
||||
|
||||
|
|
@ -295,16 +300,21 @@ CloudServer._controller = function(pReq, pRes)
|
|||
|
||||
console.log("request for " + pathname + " received...");
|
||||
|
||||
if( lConfig.rest )
|
||||
Util.exec(CloudServer.rest, {
|
||||
request : pReq,
|
||||
response : pRes
|
||||
});
|
||||
|
||||
/* если в пути нет информации ни о ФС,
|
||||
* ни об отсутствии js,
|
||||
* ни о том, что это корневой
|
||||
* каталог - загружаем файлы проэкта
|
||||
*/
|
||||
if ( !Util.isContainStr(pathname, lFS_s) &&
|
||||
!Util.isContainStr(pathname, lNoJS_s) &&
|
||||
!Util.strCmp(pathname, '/') &&
|
||||
!Util.strCmp(lQuery, 'json') ) {
|
||||
else if ( !Util.isContainStr(pathname, lFS_s) &&
|
||||
!Util.isContainStr(pathname, lNoJS_s) &&
|
||||
!Util.strCmp(pathname, '/') &&
|
||||
!Util.strCmp(lQuery, 'json') ) {
|
||||
/* если имена файлов проекта - загружаем их*/
|
||||
/* убираем слеш и читаем файл с текущец директории*/
|
||||
|
||||
|
|
@ -313,7 +323,7 @@ CloudServer._controller = function(pReq, pRes)
|
|||
console.log('reading '+lName);
|
||||
|
||||
/* watching is file changed */
|
||||
if(CloudServer.Config.appcache)
|
||||
if(lConfig.appcache)
|
||||
CloudServer.AppCache.watch(lName);
|
||||
|
||||
/* сохраняем указатель на response и имя */
|
||||
|
|
@ -372,7 +382,7 @@ CloudServer._controller = function(pReq, pRes)
|
|||
*/
|
||||
else if(lName.indexOf('min') < 0 &&
|
||||
CloudServer.Minify){
|
||||
var lMin_o = CloudServer.Config.minification,
|
||||
var lMin_o = lConfig.minification,
|
||||
|
||||
lCheck_f = function(pExt){
|
||||
return CloudFunc.checkExtension(lName,pExt);
|
||||
|
|
@ -799,7 +809,12 @@ CloudServer.sendResponse = function(pHead, pData, pName){
|
|||
}
|
||||
};
|
||||
|
||||
exports.start = function(pConfig, pIndexProcessing, pAppCachProcessing){
|
||||
CloudServer.start(pConfig, pIndexProcessing, pAppCachProcessing);
|
||||
/**
|
||||
* start server function
|
||||
* @param pConfig
|
||||
* @param pProcessing {index, appcache, rest}
|
||||
*/
|
||||
exports.start = function(pConfig, pProcessing){
|
||||
CloudServer.start(pConfig, pProcessing);
|
||||
};
|
||||
exports.CloudServer = CloudServer;
|
||||
Loading…
Add table
Add a link
Reference in a new issue