feat: add websocket scheme
This commit is contained in:
parent
3015f13e0d
commit
8904fa3fb8
9 changed files with 178 additions and 21 deletions
16
server.js
16
server.js
|
|
@ -1,21 +1,29 @@
|
|||
const app = require('./src/app')
|
||||
const { baseWebhookURL } = require('./src/config')
|
||||
const { baseWebhookURL, enableWebHook, enableWebSocket } = require('./src/config')
|
||||
const { logger } = require('./src/logger')
|
||||
const { handleUpgrade } = require('./src/websocket')
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
// Start the server
|
||||
const port = process.env.PORT || 3000
|
||||
|
||||
// Check if BASE_WEBHOOK_URL environment variable is available
|
||||
if (!baseWebhookURL) {
|
||||
// Check if BASE_WEBHOOK_URL environment variable is available when WebHook is enabled
|
||||
if (!baseWebhookURL && enableWebHook) {
|
||||
logger.error('BASE_WEBHOOK_URL environment variable is not set. Exiting...')
|
||||
process.exit(1) // Terminate the application with an error code
|
||||
}
|
||||
|
||||
app.listen(port, () => {
|
||||
const server = app.listen(port, () => {
|
||||
logger.info(`Server running on port ${port}`)
|
||||
})
|
||||
|
||||
if (enableWebSocket) {
|
||||
server.on('upgrade', (request, socket, head) => {
|
||||
handleUpgrade(request, socket, head)
|
||||
})
|
||||
}
|
||||
|
||||
// puppeteer uses subscriptions to SIGINT, SIGTERM, and SIGHUP to know when to close browser instances
|
||||
// this disables the warnings when you starts more than 10 browser instances
|
||||
process.setMaxListeners(0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue