-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
60 lines (51 loc) · 1.79 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
55
56
57
58
59
60
require('dotenv').config()
const fs = require('fs')
const express = require('express')
const app = express()
const http = require('http')
const https = require('https')
const SocketsServer = require('socket.io')
const ANALYTICS = require('stats-not-tracks')
const ROUTES = require('./my_modules/routes.js')
const SOCKETS = require('./my_modules/sockets.js')
const PROXY = require('./my_modules/proxy.js')
const BBS = require('./my_modules/bbs.js')
ANALYTICS.setup(app, {
path: `${__dirname}/data/analytics`,
admin: {
route: 'analytics',
secret: process.env.JWT_SECRET,
hash: process.env.ADMIN_PWD,
token: process.env.ADMIN_TOKEN
}
})
app.use(ROUTES)
app.use(PROXY)
app.use(express.static(`${__dirname}/www`))
const io = new SocketsServer.Server()
io.on('connection', (socket) => SOCKETS(socket, io))
BBS.listen(1337, (err) => {
if (err) return console.log(err)
console.log('bbs server is listening => telnet host 1337')
})
if (process.env.ENV === 'dev') {
// development server
const httpServer = http.createServer(app)
httpServer.listen(8000, () => console.log('listening on 8000'))
io.attach(httpServer)
ANALYTICS.live(httpServer, io)
} else {
// production servers
const credentials = {
key: fs.readFileSync('/etc/letsencrypt/live/netizen.org-0001/privkey.pem', 'utf8'),
cert: fs.readFileSync('/etc/letsencrypt/live/netizen.org-0001/cert.pem', 'utf8'),
ca: fs.readFileSync('/etc/letsencrypt/live/netizen.org-0001/chain.pem', 'utf8')
}
const httpServer = http.createServer(app)
const httpsServer = https.createServer(credentials, app)
httpServer.listen(80, () => console.log('HTTP listening on port 80'))
httpsServer.listen(443, () => console.log('HTTPS listening on port 443'))
io.attach(httpServer)
io.attach(httpsServer)
ANALYTICS.live(httpServer, io)
}