Authored by weiqingting

桩数据 路径

... ... @@ -10,7 +10,7 @@ function ContModel(app){
app.get("/1","module.index");
/*根据数据接口 渲染一个页面*/
app.get("/2","moduleA.index",["UserA-login"]);
app.get("/2","module.index",["User-login"]);
/*适配器*/
app.get("/3","moduleA.index",["UserA-login"],function(key1){
... ...
... ... @@ -6,7 +6,10 @@
method:"POST",
params:[
{name:"id",type:"Number"}
]
],
output:{
code:"我是桩数据"
}
}
}
}
\ No newline at end of file
... ...
... ... @@ -6,7 +6,10 @@
method:"POST",
params:[
{name:"id",type:"Number"}
]
],
output:{
code:"我是桩数据"
}
}
}
}
\ No newline at end of file
... ...
... ... @@ -4,7 +4,7 @@
<title></title>
</head>
<body>
<h1>Views Index 文件 {{UserA-login.code}}</h1>
<h1>Views Index 文件 {{User-login.code}}</h1>
<div>Views Index 文件 <strong>part</strong> {{>part}}</div>
<div>Views Index 文件 <strong>layout/A</strong> {{>layout/A}}</div>
<div>Views Index 文件 <strong>part</strong> {{>../../moduleA/views/index}}</div>
... ...
module.exports=function(Filter){
Filter.define("\/2","get",function(req,res,next){
Filter.define("\/3","get",function(req,res,next){
res.end("please login...");
// next();
});
... ...
'use strict';
/*下载最新node v5.10.1*/
var path = require('path');
/*获取配置接口信息*/
var apiCofig={
root:__dirname,
apps:path.join(__dirname,"apps"),
domain:"http://192.168.102.202:8088/platform",
port:3000,
log:{
consoles:["log"],
src:""
},
mock:true,
uri:'/',
MVC:{//__dirname+"/apps/{.*}/interfaces/{.*}.js"
Interfacer:path.join(__dirname,"apps/0/interfaces/1.js").replace(/0|1/g,'{.*}'),
Controller:path.join(__dirname,"apps/0/controllers/1.js").replace(/0|1/g,'{.*}'),
filters:path.join(__dirname,"filters.js")
},
use:function(app){
}
}
module.exports = require('./libs/App')(apiCofig);
\ No newline at end of file
... ...
/*下载最新node v5.10.1*/
var path = require('path');
var express = require('express');
var App = express();
var Router = express.Router();
var Scan=require("./libs/Scan");
/*获取配置接口信息*/
var apiCofig={
root:__dirname,
apps:path.join(__dirname,"apps"),
domain:"http://192.168.102.202:8088/platform",
port:3000,
log:{
consoles:["log"]
},
mock:true
}
// 记录下当前文档的路径
global.apps=apiCofig.apps;
/*日志配置和Console*/
var Console=require("./libs/Console");
Console(apiCofig.log);
console.log("YOHO!");
/*接口层*/
var Interfacer=require("./libs/Interfacer");
var InterRegisters= new Interfacer(apiCofig);
Scan("./apps/{.*}/interfaces/{.*}.js").forEach(function(src){
InterRegisters.register(require(".\/"+src));
});
/*过滤器*/
var Filter=require("./libs/Filter");
var FilterRegisters= new Filter(InterRegisters);
Scan("./filters.js").forEach(function(src){
require(".\/"+src)(FilterRegisters);
});
/*控制器层*/
var Controller=require("./libs/Controller");
var ContRegisters=new Controller(InterRegisters);
Scan("./apps/{.*}/controllers/{.*}.js").forEach(function(src){
require(".\/"+src)(ContRegisters);
});
/*路由控制*/
var KLH=function(obj,method,guid){
return function(req,res){
obj[method].call(obj,guid,req,res);
var Scan=require("./Scan");
module.exports=function(apiCofig){
// 记录下当前文档的路径
global.apps=apiCofig.apps;
/*日志配置和Console*/
var Console=require("./Console");
Console(apiCofig.log);
console.log("YOHO!");
/*接口层*/
var Interfacer=require("./Interfacer");
var InterRegisters= new Interfacer(apiCofig);
Scan(apiCofig.MVC.Interfacer).forEach(function(src){
InterRegisters.register(require(src));
});
/*过滤器*/
var Filter=require("./Filter");
var FilterRegisters= new Filter(InterRegisters);
Scan(apiCofig.MVC.filters).forEach(function(src){
require(src)(FilterRegisters);
});
/*控制器层*/
var Controller=require("./Controller");
var ContRegisters=new Controller(InterRegisters);
Scan(apiCofig.MVC.Controller).forEach(function(src){
require(src)(ContRegisters);
});
/*路由控制*/
var KLH=function(obj,method,guid){
return function(req,res){
obj[method].call(obj,guid,req,res);
}
}
}
ContRegisters.routers.forEach(function(router){
var ROU=Router.route([router.url]);
var args=FilterRegisters.use(router.url,router.method).
concat(KLH(ContRegisters,"emit",router.guid));
ROU[router.method].apply(ROU,args);
});
ContRegisters.routers.forEach(function(router){
var ROU=Router.route([router.url]);
var args=FilterRegisters.use(router.url,router.method).
concat(KLH(ContRegisters,"emit",router.guid));
ROU[router.method].apply(ROU,args);
});
App.use(apiCofig.uri, Router);
App.use('/', Router);
/*View 设置*/
var Viewer=require("./Viewer");
var Viewer=new Viewer(App,require("handlebars"));
App.set('view engine', 'html');
App.engine('html', Viewer.engine);
/*加载中间间*/
apiCofig.use&&apiCofig.use(App);
/*View 设置*/
var Viewer=require("./libs/Viewer");
var Viewer=new Viewer(App,require("handlebars"));
App.set('view engine', 'html');
App.engine('html', Viewer.engine);
var server = App.listen(apiCofig.port, function () {
var host = server.address().address;
var port = server.address().port;
});
var server = App.listen(apiCofig.port, function () {
var host = server.address().address;
var port = server.address().port;
});
\ No newline at end of file
}
\ No newline at end of file
... ...
... ... @@ -7,10 +7,15 @@
}
*/
module.exports=function(logsConfig){
var Consoles=['log', 'info', 'warn', 'error', 'dir', 'assert'];
var log=console.log;
var Consoles=['log', 'info', 'warn', 'error', 'dir', 'assert'];
var log=console.log,
info=console.info,
warn=console.warn,
error=console.error,
dir=console.dir,
assert=console.assert;
/*重写console方法*/
console.log = function(){
var args=[].slice.call(arguments, 0);
args[0]="log:"+args[0];
... ... @@ -19,7 +24,7 @@ module.exports=function(logsConfig){
console.error = function(){
var args=[].slice.call(arguments, 0);
args[0]="error:"+args[0];
log.apply(console, args);
error.apply(console, args);
};
... ... @@ -33,10 +38,9 @@ module.exports=function(logsConfig){
return !(array2.indexOf(item)>-1);
});
}
logsConfig.consoles=logsConfig.consoles||[];
if(logsConfig.consoles){
var invalidCons=difference(Consoles,logsConfig.consoles);
console.log(invalidCons);
invalidCons.forEach(function (f) {
console[f] = function () {
};
... ...
... ... @@ -49,17 +49,29 @@ function __requestApi(config,apiOpt,req,callback){
*/
Interfacer.prototype.require=function(mos,req,res,cb){
var me=this,funcs=[],names=[];
mos.forEach(function(name){
if(me.apis.hasOwnProperty(name)){
funcs.push(function(callback){
__requestApi(me.config,me.apis[name],req,callback);
});
names.push(name);
if(me.config.mock){
funcs.push(me.apis[name].output);
}else{
funcs.push(function(callback){
__requestApi(me.config,me.apis[name],req,callback);
});
}
}
});
if(funcs.length!=mos.length){
return {err:"某个key 可能不存在!"};
}
if(me.config.mock){
console.log(funcs);
cb(null,funcs,names);
return;
}
async.parallel(funcs, function(err, results){
if(err){
return cb(err,null,names);
... ...
... ... @@ -3,7 +3,7 @@ var path = require('path');
module.exports=function(url){
var tokens=[],files=[],dir="";
url.split(/\/\{|\}/).forEach(function(item,index) {
url.split(/\{|\}/).forEach(function(item,index) {
if(item){
tokens.push({
value:item,
... ... @@ -39,13 +39,15 @@ module.exports=function(url){
'folders': folderList
}
}
if(fs.statSync(tokens[0].value).isFile()){
return [path.normalize(tokens[0].value)];
}
url=url.replace(/^\W+/g,'').replace(/\//g,'\\\\').replace(/\{/g,'(').replace(/\}/g,'?)');
url=url.replace(/^\W+/g,'').replace(/\\/g,'\\\\').replace(/\{/g,'(').replace(/\}/g,'?)');
var regex = new RegExp("^"+url+"$");
var obj=scanFolder(tokens[0].value),result=[];
if(path.extname(url)){
result=obj.files.filter(function(item){
... ...