-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (50 loc) · 1.5 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
const express=require('express')
//const path=require('path')
const port=process.env.PORT||3000
const mongoose=require('mongoose')
const session=require('express-session')
const mongoStore=require('connect-mongo')(session)
const dbUrl='mongodb://localhost/weibo1'
const bodyParser=require('body-parser')
const moment=require('moment')
const morgan = require('morgan')
const multipart = require('connect-multiparty')
const path=require('path')
const fs = require('fs')
//const multipartMiddleware = multipart()
//const Weibo= require('./app/models/weibo')
mongoose.Promise = global.Promise
mongoose.connect(dbUrl)
mongoose.connection.on('connected', function(){
console.log('Connection success!');
});
mongoose.connection.on('error', function(err){
console.log('Connection error: ' + err);
});
mongoose.connection.on('disconnected', function(){
console.log('Connection disconnected');
});
app=express()
app.set('views', './views/pages')
app.set('view engine', 'ejs')
app.locals.moment=moment
app.locals.user=false
app.use(express.static('./public'))
app.use(morgan(':method :url :status'))
app.use(session(
{
secret:'weibo',
name:'user',
resave:false,
saveUninitialized: true,
store:new mongoStore({ //将session存储到mongodb数据库
url:dbUrl,
collection:'session'
})
})
)
app.use(bodyParser.urlencoded({extended:true}))
//app.use(multipartMiddleware)
require('./config/routes')(app)
app.listen(port)
console.log('weibo started on port ' + port)