switched to f** ESS modules

This commit is contained in:
STEINNI
2025-09-14 21:06:13 +00:00
parent f4ac7df4a7
commit b4cd02add5
16 changed files with 63 additions and 49 deletions
+13 -12
View File
@@ -1,13 +1,14 @@
const yargs = require('yargs')
const ws = require('ws')
const fs = require('fs')
const RedisConnexion = require('./redisConnexion')
const urlparser = require('url');
const wssServer = require('./wssServer')
const configHelper = require('./configHelper')
import yargs from 'yargs/yargs'
import { hideBin } from 'yargs/helpers'
import { WebSocketServer } from 'ws'
import fs from 'fs'
import {RedisConnexion} from './redisConnexion.js'
import urlparser from 'url'
import {wssServer} from './wssServer.js'
import {configHelper} from './configHelper.js'
const argv = yargs.command('wssGateway', 'Redis <=> Websocket message bus gateway', {})
const argv = yargs(hideBin(process.argv)).command('wssGateway', 'Redis <=> Websocket message bus gateway', {})
.options({
'argv.debug': {
description: 'shows debug info',
@@ -36,15 +37,15 @@ async function startRedis(wssGatewayConfig) {
}
cfgh.fetchConfig().then( wssGatewayConfig => {
cfgh.fetchConfig().then( async wssGatewayConfig => {
if((!wssGatewayConfig) || (Object.keys(wssGatewayConfig).length<4)) {
console.error('Cannot get a valid configuration ! Aaarrghhh...')
process.exit()
}
let httpLib
if(wssGatewayConfig.server.unsecure) httpLib = require('http')
else httpLib = require('https')
if(wssGatewayConfig.server.unsecure) httpLib = await import('http')
else httpLib = await import('https')
/////////////////////// Create & Start servers \\\\\\\\\\\\\\\\\\\\\\
@@ -91,7 +92,7 @@ cfgh.fetchConfig().then( wssGatewayConfig => {
wssServerOptions['key'] = fs.readFileSync(wssGatewayConfig.server.certKeyFile)
wssServerOptions['cert'] = fs.readFileSync(wssGatewayConfig.server.certFile)
}
const WSSServer = new ws.WebSocketServer(wssServerOptions);
const WSSServer = new WebSocketServer(wssServerOptions);
console.log(`WS${wssGatewayConfig.server.unsecure ? '': 'S'} server created for ${wssGatewayConfig.server.listenHost}:${wssGatewayConfig.server.listenPort}`)
startRedis(wssGatewayConfig).then((rediscnx) => {