-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
94 lines (82 loc) · 3.59 KB
/
index.js
File metadata and controls
94 lines (82 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// +----------------------------------------------------------------------
// | MINO [ WHAT DO YOU NODE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2012 http://www.xiaomi.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: cupdir <cupdir@gmail.com>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* MONO 入口文件
+------------------------------------------------------------------------------
* @package node
* @author cupdir <cupdir@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
var server = require('./system/system'); //加载系统配置
require(server.config.ROOT_PATH+'/core/init');//初始化各种配置
/**
* 任务转发处理 http://expressjs.com/guide.html
* @param object request HTTP对象
* @param object response 请求对象
*/
server.MI.get('/', function(request,response){
response.writeHead(200, {
'Content-Type': 'text/html'
});
response.end('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>'+
'<h3 style=\'color:gray\'>MINO </h3><br>'+
'</body>');
});
server.MI.get("/:module/:method.:format?", function(request,response){
if(request.params.format == 'json'){
response.header('Content-Type', 'application/json; charset=utf-8');
}
response.header('Server', 'MINO/1.0');
response.header('X-Powered-By', 'xiaomi');
try{
if(/^[a-zA-Z]+$/.test(request.params.method) == false){
console.log('+--------------------------------------+');
console.log(request.params.method+'\t接口方法命名不正确');
response.end(request.params.method+'\t接口方法命名不正确');
console.log('+--------------------------------------+');
return;
}
var service = require(server.config.ROOT_PATH+'/module/'+request.params.module),
callback = 'service.api.'+request.params.method+'(request,response,server)';
if(typeof(service.api) == 'undefined'){
console.log('+--------------------------------------+');
console.log('\t没有实现service.api对象');
response.end('\t没有实现service.api对象');
console.log('+--------------------------------------+');
return;
}
eval(callback);
}catch(err) {
console.log('+--------------------------------------+');
console.log(err);
response.end("\t系统错误\n"+err);
console.log('+--------------------------------------+');
}
//response.end();
});
server.MI.listen(server.config.LISTEN_PORT);//开启监听
console.log('+--------------------------------------+');
console.log('\t服务器:' + 'http://10.237.35.154:8000/');
console.log('\t平台版本:' + process.platform)
console.log('\t版本号: ' + process.version);
console.log("\t进程号:" + process.pid);
console.log(util.inspect(process.memoryUsage()));
console.log('+--------------------------------------+');
/**
* 进程事件
*/
process.on('uncaughtException', function (err) {
console.log('+--------------------------------------+');
console.log(err);
console.log('+--------------------------------------+');
});