-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (37 loc) · 1.09 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
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 http = require('http').Server(app)
const sockets = require('./server/socket')
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)
sockets.getSocketio(http)
// 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:32768/blogs'
// })
// }))
app.get('*', function (req, res) {
let html = fs.readFileSync(resolve('./' + 'index.html'), 'utf-8')
res.send(html)
})
http.listen(4000, function () {
console.log('访问地址为 localhost:4000')
})