forked from chaohangz/vueBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (34 loc) · 970 Bytes
/
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
const express = require('express')
const fs = require('fs')
const path = require('path')
const bodyParse = require('body-parser')
const session = require('express-session')
const MongoStore = require('connect-mongo')(session)
const router = require('./server/router')
const app = express()
const resolve = file => path.resolve(__dirname, file)
app.use('/dist', express.static(resolve('./dist')))
app.use(bodyParse.json())
app.use(bodyParse.urlencoded({ extended: true }))
app.use(router)
// session
app.set('trust proxy', 1) // trust first proxy
app.use(session({
secret: 'blog',
resave: false,
saveUninitialized: true,
cookie: {
secure: true,
maxAge: 2592000000
},
store: new MongoStore({
url: 'mongodb://localhost:27017/blog'
})
}))
app.get('*', function (req, res) {
let html = fs.readFileSync(resolve('./' + 'index.html'), 'utf-8')
res.send(html)
})
app.listen(3000, function () {
console.log('访问地址为 localhost:3000')
})