forked from surmon-china/surmon.me
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·42 lines (34 loc) · 1.04 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
const app = require('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 || 3000
process.noDeprecation = true
// extend
const webrtcServer = require('./webrtc.server.js')
const barrageServer = require('./barrage.server.js')
app.set('port', port)
// Import and Set Nuxt.js options
const config = require('./nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
// 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()}`)
// barrage server
barrageServer(io)
// webrtc Server
webrtcServer(io)