-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathapp.js
54 lines (38 loc) · 1.29 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
var express = require('express');
var app = express();
var path = require('path');
var mongoose = require("mongoose");
var bodyParser = require('body-parser');
var multer = require('multer');
var session = require('express-session');
global.dbHelper = require( './common/dbHelper' );
global.db = mongoose.connect("mongodb://127.0.0.1:27017/test1");
app.use(session({
secret:'secret',
cookie:{
maxAge:1000*60*30
}
}));
// 设定views变量,意为视图存放的目录
app.set('views', path.join(__dirname, 'views'));
// 设定view engine变量,意为网页模板引擎
//app.set('view engine', 'ejs');
app.set( 'view engine', 'html' );
app.engine( '.html', require( 'ejs' ).__express );
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(multer());
// 设定静态文件目录,比如本地文件
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req, res, next){
res.locals.user = req.session.user;
var err = req.session.error;
res.locals.message = '';
if (err) res.locals.message = '<div class="alert alert-danger" style="margin-bottom: 20px;color:red;">' + err + '</div>';
next();
});
require('./routes')(app);
app.get('/', function(req, res) {
res.render('login');
});
app.listen(3000);