-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
37 lines (34 loc) · 1.09 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
var http = require('http'),
fs = require('fs'),
_ = require('underscore'),
express = require('express'),
mode = _.isNumber(process.env['APP_PORT']) ?
'bae':
_.isNumber(process.env['VMC_APP_PORT']) ?
'mopaas':
'local',
config = require('./config/')(mode),
run = require('./lib/run'),
removeDir = require('./lib/removedir'),
app = express();
// 确保目录存在
var contentDir = config.contentDir,
tmpDir = config.tmpDir,
shareDir = config.shareDir;
fs.existsSync(contentDir) || fs.mkdirSync(contentDir);
fs.existsSync(tmpDir) || fs.mkdirSync(tmpDir);
removeDir(shareDir);
fs.mkdirSync(shareDir);
app.set('env', config.env);
app.use(express.favicon());
app.use(express.bodyParser({uploadDir: config.tmpDir}));
app.use(express.cookieParser());
app.use(express.session({secret: config.secret}));
run(app, config); // 上层运作
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);
});