Authored by weiqingting

yo2 修改一些细节

... ... @@ -10,24 +10,28 @@ function ContModel(app){
app.get("/1","module.index");
/*根据数据接口 渲染一个页面*/
app.get("/2","module.index",["User-login"]);
app.get("/2","module.index","User-login");
/*接口 类型为数组或者字符串 返回值区别 */
app.get("/3","module.index",["User-login"]);
/*适配器*/
app.get("/3","moduleA.index",["UserA-login"],function(key1){
key1.userName="我修改了适配器";
app.get("/4","module.index",["User-login"],function(key1){
key1.message="我修改了适配器";
return key1;
});
/*express 基本功能*/
app.get("/4",function(req,res){
app.get("/5",function(req,res){
/*注意 render 的View*/
res.render("moduleA.index",{});
});
/**/
app.get("/5",["UserA-login"],function(key1,req,res){
app.get("/6/:id",["User-login"],function(key1,req,res){
/*注意 render 的View*/
res.json(key1);
res.end(req.query.id);
});
/*
... ...
... ... @@ -8,7 +8,8 @@
{name:"id",type:"Number"}
],
output:{
code:"我是桩数据"
code:"我是桩数据=code",
message:"我是桩数据=messsage"
}
}
}
... ...
... ... @@ -4,9 +4,10 @@
<title></title>
</head>
<body>
<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>
<h1>Hello word 你所打开的是module模块下views index.html</h1>
<h1>User-login.code:{{User-login.code}}</h1>
<div><strong>part</strong> {{>part}}</div>
<div><strong>layout/A</strong> {{>layout/A}}</div>
<div><strong>../../moduleA/views/index</strong>===> {{>../../moduleA/views/index}}</div>
</body>
</html>
... ...
View Layout A {{key1}}
{{>../../../moduleA/views/index}}
<strong>../../../moduleA/views/index</strong> ===> {{>../../../moduleA/views/index}}
... ...
part {{key2}}
\ No newline at end of file
message 输出 {{message}}
\ No newline at end of file
... ...
我是 moduleA views index 文件
../../module/view/part {{> ../../module/views/part}}
<strong>../../module/view/part</strong>===> {{> ../../module/views/part}}
... ...
module.exports=function(Filter){
Filter.define("\/3","get",function(req,res,next){
Filter.define("\/5","get",function(req,res,next){
res.end("please login...");
// next();
});
... ...
... ... @@ -14,7 +14,7 @@ var apiCofig={
src:""
},
mock:true,
uri:'/',
baseUrl:'/',
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,'{.*}'),
... ...
... ... @@ -2,6 +2,10 @@ var path = require('path');
var express = require('express');
var App = express();
var bodyParser = require('body-parser');
var multer = require('multer');
var Router = express.Router();
var Scan=require("./Scan");
... ... @@ -20,6 +24,7 @@ module.exports=function(apiCofig){
/*接口层*/
var Interfacer=require("./Interfacer");
var InterRegisters= new Interfacer(apiCofig);
apiCofig.MVC.Interfacer&&
Scan(apiCofig.MVC.Interfacer).forEach(function(src){
InterRegisters.register(require(src));
});
... ... @@ -27,18 +32,25 @@ module.exports=function(apiCofig){
/*过滤器*/
var Filter=require("./Filter");
var FilterRegisters= new Filter(InterRegisters);
apiCofig.MVC.filters&&
Scan(apiCofig.MVC.filters).forEach(function(src){
require(src)(FilterRegisters);
});
/*控制器层*/
var Controller=require("./Controller");
var ContRegisters=new Controller(InterRegisters);
apiCofig.MVC.Controller&&
Scan(apiCofig.MVC.Controller).forEach(function(src){
require(src)(ContRegisters);
});
/*内置中间件 对Http请求解析*/
App.use(bodyParser.json()); // for parsing application/json
App.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
// App.use(multer()); // for parsing multipart/form-data
/*路由控制*/
var KLH=function(obj,method,guid){
... ... @@ -53,7 +65,7 @@ module.exports=function(apiCofig){
ROU[router.method].apply(ROU,args);
});
App.use(apiCofig.uri, Router);
App.use(apiCofig.baseUrl, Router);
/*View 设置*/
... ...
... ... @@ -23,7 +23,11 @@ Controller.prototype.__parseReq=function(req){
}
Controller.prototype.__define=function(method,router,view,apis,callback){
var me=this;
var me=this,isObj=false;
if(typeof apis=="string"){
apis=[apis];
isObj=true;
}
/*参数验证*/
var guid=md5(router+":"+method)
... ... @@ -47,7 +51,11 @@ Controller.prototype.__define=function(method,router,view,apis,callback){
}else{
interfaces.forEach(function(item,index){
model[names[index]]=item;
if(isObj){
model=item;
}else{
model[names[index]]=item;
}
});
}
if(model){
... ... @@ -70,21 +78,16 @@ Controller.prototype.__define=function(method,router,view,apis,callback){
}
Controller.prototype.get=function(router,views,apis,callback){
var me=this;
if(toString.call(views)=='[object Array]'){
if(!(typeof views=="string"&&views.indexOf('.')>-1)){
callback=apis;
apis=views;
views=null;
}else if(typeof views =='function'){
callback=views;
apis=[];
views=null;
}
if(typeof apis=="function"){
if(typeof apis =='function'){
callback=apis;
apis=[];
}
apis=apis||[];
me.__define("get",router,views,apis,callback);
}
Controller.prototype.post=function(router,apis,callback){
... ...
... ... @@ -68,7 +68,6 @@ Interfacer.prototype.require=function(mos,req,res,cb){
return {err:"某个key 可能不存在!"};
}
if(me.config.mock){
console.log(funcs);
cb(null,funcs,names);
return;
}
... ...