-
Notifications
You must be signed in to change notification settings - Fork 27
/
app.js
24 lines (21 loc) · 820 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
import app from './server.js'
import fs from 'fs/promises'
import https from 'https'
const PORT = parseInt(process.env.WS_PORT) || 4003
const HTTPS = process.env.WS_HTTPS.toLocaleLowerCase() === 'true'
const PRIVATE_KEY = process.env.WS_PRIVATE_KEY
const CERTIFICATE = process.env.WS_CERTIFICATE
if (HTTPS) {
https.globalAgent.maxSockets = Infinity
const privateKey = await fs.readFile(PRIVATE_KEY, 'utf8')
const certificate = await fs.readFile(CERTIFICATE, 'utf8')
const credentials = { key: privateKey, cert: certificate }
const httpsServer = https.createServer(credentials, app)
httpsServer.listen(PORT, () => {
console.log('HTTPS server is running on Port:', PORT)
})
} else {
app.listen(PORT, () => {
console.log('HTTPS server is running on Port:', PORT)
})
}