-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
58 lines (46 loc) · 1.46 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
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var mongoose = require('mongoose');
var mongoStore = require('connect-mongo')(session);
//config
var config = require('./config');
var dbUrl = 'mongodb://localhost/msgweb';
var port = process.env.PORT || 3000;
var app = express();
mongoose.connect(dbUrl);
// view engine setup
app.set('views', path.join(__dirname, './app/views/pages'));
app.set('view engine', 'pug');
// uncomment after placing your favicon in /public
app.use(favicon(path.join(__dirname, 'public', 'favicon.png')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(session({
secret:'imooc',
resave: false,
saveUninitialized: true,
store:new mongoStore({
url:dbUrl,
collection: 'sessions'
})
}));
app.use(express.static(path.join(__dirname, 'public')));
var env = process.env.NODE_ENV || 'development';
if('development' === env){
app.set('showStackError', true);
app.use(logger(':method :url :status'));
app.locals.pretty = true;
mongoose.set('debug', true);
}
app.locals.title = config.web.title;
app.locals.memu = config.web.memu;
app.locals.moment = require('moment'),
require('./route')(app);
app.listen(port);
console.log('msg_web started on port '+port);