forked from zs1621/zsblog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
69 lines (51 loc) · 1.86 KB
/
config.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
module.exports = function(express, app){
var mongoose = require('mongoose');
var MongoStore = require('connect-mongo')(express);//save session in mongodb
var partials = require('express-partials');//layout use
var flash = require('connect-flash');//error show
//connect mongodb
var DB_URL = "mongodb://localhost:27017/zsblog";
mongoose.connect(DB_URL);
app.configure(function(){
app.set('port', process.env.port || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.engine('ejs', require('ejs').__express);
app.use(partials());
app.use(flash());
app.use(express.favicon());
// app.use(express.bodyParser({
// keepExtensions: true,
// uploadDir: __dirname+'/public/img'
// }));//upload file path
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({
store: new MongoStore({ url: DB_URL }),
secret: 'mysecret',
cookie: { maxAge: 365 * 24 * 60 * 60 * 1000 }}));
app.use(app.router);
app.use(express.static(__dirname+'/public'));
app.use(function(req,res,next){
res.render('404',{title:404,layout:false});
});//404 handle
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true}));
});
app.configure('production', function(){
app.use(express.errorHandler());
app.use(function(err,req,res,next){
console.error(err.stack);
res.send(500, 'Something broke!');
});
});
app.use(function(req,res,next){
res.locals.user = req.session ? req.session.user:'';
res.locals.keyword = req.session ? req.session.keyword:'';
res.locals.error = req.session ? req.session.error:'';
res.locals.success = req.session ? req.session.success:'';
});
}