UNPKG

3.66 kBJavaScriptView Raw
1var node = require('./lib/node');
2var express = require('./lib/express');
3var mysql = require('./lib/mysql');
4var redis = require('./lib/redis');
5var comm = require('./lib/comm/index');
6
7var g_app = {
8 v_upload: {},
9 v_singleCoreProcess: false,
10 m_apparatus: comm.apparatus,
11 m_convert: comm.convert,
12 m_cryptogram: comm.cryptogram,
13 m_encode: comm.encode,
14 m_obj: comm.obj,
15 m_obtain: comm.obtain,
16 m_request: comm.request,
17 m_verify: comm.verify,
18 m_ucpaas: require('./lib/ucpaas-sms/index.js'),
19 m_wechat : require('./lib/wechat.js')
20};
21
22if (process.argv) {
23 if (process.argv.length) {
24 g_app.v_singleCoreProcess = process.argv[process.argv.length - 1].indexOf('-d') == 0 ? true : false
25 }
26 else {
27 g_app.v_singleCoreProcess = process.argv[0].indexOf('-d') == 0 ? true : false
28 }
29}
30
31var app = function () {
32 return g_app;
33};
34exports.app = g_app;
35
36//运行Express
37var runExpress = function (conf, middleware) {
38 express.runExpress(conf, middleware);
39}
40
41//运行Node
42var runNode = function (conf, all, middleware) {
43 node.runNode(conf, all, middleware);
44}
45exports.runNode = runNode;
46
47//运行Mysql
48var runMysql = function (conf) {
49 g_app.m_mysql = mysql.runMysql(conf);
50 return g_app.mysql;
51}
52exports.runMysql = runMysql;
53
54//运行Redis
55var runRedis = function (conf) {
56 g_app.m_redis = redis.runRedis(conf);
57 return g_app.m_redis;
58}
59exports.runRedis = runRedis;
60
61//运行所有服务
62var runAllServer = function (conf, middleware) {
63 runNode(conf, true, middleware);
64}
65exports.runAllServer = runAllServer;
66
67//重写console的log、info、warn、error方法
68(function () {
69 setTimeout(function () {
70 var ismain = false;
71 var c_log = console.log;
72 console.log = function () {
73 var date = (new Date()).Format();
74 c_log(['------[LOG PID:' + process.pid.toString() + (ismain ? '(MAIN)' : '') + ' TIME:' + date + ']------']);
75 for (var key in arguments) {
76 c_log(arguments[key]);
77 }
78 c_log(['------[LOG PID:' + process.pid.toString()+ (ismain ? '(MAIN)' : '') + ' TIME:' + date + ']------']);
79 c_log();
80 };
81 var c_info = console.info;
82 console.info = function () {
83 var date = (new Date()).Format();
84 c_info(['------[INFO PID:' + process.pid.toString() + ' TIME:' + date + ']------']);
85 for (var key in arguments) {
86 c_info(arguments[key]);
87 }
88 c_info(['------[INFO PID:' + process.pid.toString() + ' TIME:' + date + ']------']);
89 c_log();
90 };
91 var c_warn = console.warn;
92 console.warn = function () {
93 var date = (new Date()).Format();
94 c_warn(['------[WARN PID:' + process.pid.toString() + ' TIME:' + date + ']------']);
95 for (var key in arguments) {
96 c_warn(arguments[key]);
97 }
98 c_warn(['------[WARN PID:' + process.pid.toString() + ' TIME:' + date + ']------']);
99 c_log();
100 };
101 var c_error = console.error;
102 console.error = function () {
103 var date = (new Date()).Format();
104 c_error(['------[ERROR PID:' + process.pid.toString() + ' TIME:' + date + ']------']);
105 for (var key in arguments) {
106 c_error(arguments[key]);
107 }
108 c_error(['------[ERROR PID:' + process.pid.toString() + ' TIME:' + date + ']------']);
109 c_log();
110 };
111 }, 5000);
112})();
\No newline at end of file