|
|
/*下载最新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 |
...
|
...
|
|