-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
79 lines (70 loc) · 2.39 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
// tjob web
var express = require('express');
var jqtpl = require("jqtpl");
var path = require('path');
var fs = require('fs');
var config = require('./config.js');
var weibo = require('weibo');
var utillib = require('./public/js/util.js');
var uploadfile = require('./lib/uploadfile');
var RedisStore = require('connect-redis')(express);
var user = require('./routes/user');
var static_options = { maxAge: 3600000 * 24 * 30 };
var MAX_AGE = 3600 * 24 * 14;
var app = express.createServer(
express.bodyParser({ uploadDir: config.FILE_DIR, keepExtensions: true }),
express.static(__dirname + '/public', static_options),
express.cookieParser(),
express.session({
secret: config.session.secret,
store: new RedisStore({host: config.session.host})
}),
user.oauth_handle,
express.errorHandler({ dumpExceptions: true, showStack: true })
);
var logger_options = {
format: ':http-version|:method|:url|:status|:response-time|:remote-addr|:referrer|:date|:user-agent'
};
if (!config.debug) {
//日志格式
var log_path = path.join(__dirname, 'web.log');
console.log('log file:', log_path);
var log_write_stream = fs.createWriteStream(log_path, { flags: 'a' });
process.on('exit', function() {
console.log('process exit, log end()');
log_write_stream.end();
});
logger_options.stream = log_write_stream;
}
// use jqtpl in express
app.set("view engine", "html");
app.set("jsonp callback", "callback");
app.register(".html", jqtpl.express);
app.set('view options', {
layout: 'layout.html'
});
app.helpers({
config: config
});
user(app); // must first
require('./routes/job')(app);
require('./routes/resume')(app);
require('./routes/tag')(app);
require('./routes/site')(app);
// 设置文件上传
var upload_dir = config.FILE_DIR + '/upload';
utillib.mkdirs(upload_dir, '777', function(){
app.post('/upload', uploadfile.upload(upload_dir));
app.get('/down/:name', uploadfile.download(upload_dir, {field: 'name'}));
// 查看简历
app.get('/download', uploadfile.download(config.FILE_DIR, {field: 'p'}));
});
app.listen(config.site.port);
console.log(new Date() + ' web server start at ' + config.site.homeurl);
//catch all exception
process.on('uncaughtException', function (err) {
console.error('Uncaught exception: ' + err);
console.error(err.message);
console.error(err.stack);
process.exit();
});