-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·54 lines (43 loc) · 1.37 KB
/
server.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
const cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
const express = require('express')
const app = express()
const server = require('http').Server(app)
const io = require('socket.io')(server)
const { Nuxt, Builder } = require('nuxt')
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 5000
process.noDeprecation = true
// extend
// const webrtcServer = require('./webrtc.server')
// const barrageServer = require('./barrage.server')
// const updateGAScript = require('./utils/update-analytics')
app.set('port', port)
// Import and Set Nuxt.js options
const config = require('./nuxt.config')
config.dev = !(process.env.NODE_ENV === 'production')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cookieParser())
// Init Nuxt.js
const nuxt = new Nuxt(config)
app.use(nuxt.render)
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
builder.build().catch((error) => {
// eslint-disable-line no-console
console.error(error)
process.exit(1)
})
}
// Listen the server
server.listen(port, host)
// eslint-disable-line no-console
console.log(`Nuxt.js SSR Server listening on ${host}:${port}, at ${new Date().toLocaleString()}`)
// // 更新 GA 脚本
// updateGAScript()
// // barrage server
// barrageServer(io)
// // webrtc Server
// webrtcServer(io)