-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (39 loc) · 1.34 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
var express = require('express');
var app = express();
var path = require('path');
var mongoose = require("mongoose");
global.fs = require("fs");
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/work5");
app.use(session({
secret:'secret',
cookie:{
maxAge:1000*60*30
}
}));
// 设定views变量,意为视图存放的目录
app.set('views', path.join(__dirname, 'views/pages'));
// 设定view engine变量,意为网页模板引擎
//app.set('view engine', 'ejs');
app.set( 'view engine', 'twig' );
// app.engine( '.html', require( 'twig' ).__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" >' + err + '</div>';
next();
});
require('./routes')(app);
app.get('/', function(req, res) {
res.render('login');
});
app.listen(3000);