-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (38 loc) · 1.15 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
var http = require('http'),
fs = require('fs'),
_ = require('underscore'),
express = require('express'),
mode = (process.argv && process.argv[2]) || 'bae', // 运行模式
config = global.config = require('./config/')(mode),
app = global.app = express(),
wxbase = require('./lib/wxbase/');
app.configure(function() {
// 确保目录存在
_.each(['publicDir', 'voiceDir'], function(val) {
fs.existsSync(config[val]) || fs.mkdir(config[val]);
});
app.set('env', config.env);
app.use(express.favicon());
app.use(express.bodyParser({uploadDir: config.tmpDir}));
app.use(require('./lib/rawbody'));
});
// 使用 wxbase
wxbase({
app: app,
wxPath: config.wxPath,
wxToken: config.wxToken,
wxHandler: require('./lib/my-wx-handler').init({
app: app,
hostUrl: config.hostUrl,
publicDir: config.publicDir,
voiceDir: config.voiceDir,
wxAccount: config.wxAccount
}),
wxValidPost: config.wxValidPost
});
app.use(express.static(config.publicDir));
http.createServer(app).on('error', function(err) {
throw new Error('Port ' + config.port + ' Occupied');
}).listen(config.port, function() {
console.log('Listening on port ' + config.port);
});