-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
92 lines (78 loc) · 2.33 KB
/
app.js
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
91
92
/**
* Module dependencies.
*/
var express = require('express'),
bodyParser = require('body-parser'),
multipart = require('connect-multiparty'),
cookieParser = require('cookie-parser'),
//session = require('express-session'),
//serveStatic = require('serve-static'),
methodOverride = require('method-override'),
morgan = require('morgan'), //logger
errorHandler = require('errorhandler');
//viewCache = require('express-view-cache');
//MongoStore = require('connect-mongo')(session);
//MongoStore = require('connect-mongo')(express);
var http = require('http'),
path = require('path');
var wechat = require('./src/services/wechat');
var constdata = require('./src/common/constdata'),
config = require('./src/config/config.json'),
router = require('./src/base/router'),
core = require('./src/base/core');
var app = express();
//app.configure
(function() {
app.set('port', process.env.PORT || 3005);
//app.use(viewCache(5000, {'type':'application/json', 'driver':'memory'}));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
//app.use(express.favicon());
app.use(bodyParser.urlencoded({
extended: true,
uploadDir: constdata.TMP_DIR
}));
//4.x multipart
app.use(multipart({
uploadDir: constdata.TMP_DIR
}));
app.use(cookieParser());
/*app.use(session({
secret: config.SESSION_KEY,
store: new MongoStore({
db: config.DB_NAME,
collection: config.DB_PREFIX + 'sessions',
host: config.DB_HOST,
port: config.DB_PORT,
username: config.DB_USER,
password: config.DB_PASS,
})
}));*/
app.use(methodOverride());
//nginx process
app.use(express.static(constdata.PUBLIC_DIR));
app.use(core.coreMiddleware);
app.use('/wechat', wechat.Middleware());
router.route(app, express);
router.routeErrorPage(app, express);
})();
var node_env = process.env.NODE_ENV;
console.log("NODE_ENV: " + node_env);
if (!node_env) {
node_env = 'development';
}
// default configure is development
// 4.x
switch (node_env) {
case 'development':
app.use(morgan('dev'));
app.use(errorHandler());
break;
case 'production':
app.use(errorHandler());
app.set('view cache', true);
break;
}
http.createServer(app).listen(app.get('port'), function() {
console.log("Express server listening on port " + app.get('port'));
});