switched to f** ESS modules
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
module.exports = class AccesRights {
|
||||
export class AccesRights {
|
||||
|
||||
constructor(config, debug){
|
||||
this.debug = debug
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
module.exports.methods = {
|
||||
export const methods = {
|
||||
|
||||
/* Creates (predictable) peer-to-peer chan if necessary, or check for lobby existence, then subscribe to it.
|
||||
Request:
|
||||
|
||||
+15
-7
@@ -1,9 +1,17 @@
|
||||
module.exports.methods = {}
|
||||
Object.assign(module.exports.methods, require('./utilities').methods )
|
||||
Object.assign(module.exports.methods, require('./pubSub').methods )
|
||||
Object.assign(module.exports.methods, require('./store').methods )
|
||||
Object.assign(module.exports.methods, require('./sessions').methods )
|
||||
Object.assign(module.exports.methods, require('./notifications').methods )
|
||||
Object.assign(module.exports.methods, require('./chat').methods )
|
||||
import { methods as utilities } from './utilities.js'
|
||||
import { methods as pubSub } from './pubSub.js'
|
||||
import { methods as store } from './store.js'
|
||||
import { methods as sessions } from './sessions.js'
|
||||
import { methods as notifications } from './notifications.js'
|
||||
import { methods as chat } from './chat.js'
|
||||
|
||||
export const gatewayActions = {
|
||||
...utilities,
|
||||
...pubSub,
|
||||
...store,
|
||||
...sessions,
|
||||
...notifications,
|
||||
...chat
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports.methods = {
|
||||
export const methods = {
|
||||
|
||||
async action_NOTIFS(action, payload, reqid){
|
||||
let reply = {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
module.exports.methods = {
|
||||
export const methods = {
|
||||
/* Request:
|
||||
{
|
||||
"action": "SUB",
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
module.exports.methods = {
|
||||
export const methods = {
|
||||
|
||||
/* Request payload : null
|
||||
Reply:
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
module.exports.methods = {
|
||||
export const methods = {
|
||||
|
||||
/* Request:
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports.methods = {
|
||||
export const methods = {
|
||||
|
||||
/* Request:
|
||||
{
|
||||
|
||||
+9
-8
@@ -1,9 +1,8 @@
|
||||
const Ajv = require("ajv")
|
||||
const confSchema = require('./configSchema.json')
|
||||
import Ajv from 'ajv'
|
||||
import confSchema from './configSchema.json' with { type: 'json' }
|
||||
import { pathToFileURL } from 'url'
|
||||
|
||||
let DynamoDBClient, GetItemCommand, marshall, unmarshall
|
||||
|
||||
module.exports = class configHelper {
|
||||
export class configHelper {
|
||||
|
||||
constructor(options){
|
||||
this.config = {}
|
||||
@@ -24,7 +23,10 @@ module.exports = class configHelper {
|
||||
|
||||
async fetchConfigFile(){
|
||||
let curConfig = this.config
|
||||
this.config = await require(this.localfile)
|
||||
const url = pathToFileURL(this.localfile).href
|
||||
this.config = await import(url, {
|
||||
with: { type: 'json' }
|
||||
}).then(m => m.default)
|
||||
if(this.isValidConfig(this.config)) return(this.config)
|
||||
console.error(this.isValidConfig.errors)
|
||||
//revert if invalid conf
|
||||
@@ -37,9 +39,8 @@ module.exports = class configHelper {
|
||||
}
|
||||
|
||||
async refreshAccessRightsFile(){
|
||||
delete require.cache[require.resolve(this.localfile)]
|
||||
let tmp
|
||||
try { tmp = require(this.localfile) }
|
||||
try { tmp = import(`${this.localfile}?update=${Date.now()}`, { assert: { type: 'json' } }) }
|
||||
catch(err) {
|
||||
console.error('Error Reloading config !! (bad json?) => Keeping current accessRights !')
|
||||
return
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"version": "3.4.6",
|
||||
"description": "Websocket-Redis Message Bus Gateway",
|
||||
"main": "wssGateway.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "jest --verbose"
|
||||
},
|
||||
@@ -15,6 +16,8 @@
|
||||
"dependencies": {
|
||||
"ajv": "^8.12.0",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"express-mysql-session": "^3.0.3",
|
||||
"express-session": "^1.18.2",
|
||||
"pm2": "^6.0.10",
|
||||
"redis": "^4.3.0",
|
||||
"urldecode": "^1.0.1",
|
||||
|
||||
+2
-3
@@ -1,6 +1,5 @@
|
||||
const redis = require('redis');
|
||||
|
||||
module.exports = class RedisConnexion {
|
||||
import redis from 'redis'
|
||||
export class RedisConnexion {
|
||||
|
||||
constructor(options) {
|
||||
this.config = options.config;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const AccesRights = require('../accesRights')
|
||||
import {AccesRights} from '../accesRights'
|
||||
let accessRights = new AccesRights({
|
||||
"accessRights": [
|
||||
{
|
||||
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
const crypto = require('crypto')
|
||||
const gatewayActions = require('./actions')
|
||||
import crypto from 'crypto'
|
||||
import { gatewayActions } from './actions/index.js'
|
||||
|
||||
module.exports = class WssConnexion {
|
||||
export class WssConnexion {
|
||||
|
||||
constructor(options){
|
||||
Object.assign(this, gatewayActions.methods)
|
||||
Object.assign(this, gatewayActions)
|
||||
|
||||
this.config = options.config;
|
||||
this.socket = options.socket;
|
||||
|
||||
+13
-12
@@ -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) => {
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
"serviceName": "wssGateway",
|
||||
"server": {
|
||||
"listenHost": "0.0.0.0",
|
||||
"listenPort": 4443,
|
||||
"listenPort": 3999,
|
||||
"listenPath": "/msgbus",
|
||||
"keepAliveInterval": "30",
|
||||
"keepAliveTimeout": "5",
|
||||
"certFile": "/etc/letsencrypt/live/eismea.internike.com/fullchain.pem",
|
||||
"certKeyFile": "/etc/letsencrypt/live/eismea.internike.com/privkey.pem",
|
||||
"certFile": "/etc/letsencrypt/live/42.internike.com/fullchain.pem",
|
||||
"certKeyFile": "/etc/letsencrypt/live/42.internike.com/privkey.pem",
|
||||
"challengeExpiration": 20,
|
||||
"unsecure": false,
|
||||
"healthCheckPath": "/status",
|
||||
|
||||
+6
-4
@@ -1,8 +1,10 @@
|
||||
const AccesRights = require('./accesRights')
|
||||
const crypto = require('crypto')
|
||||
const WssConnexion = require('./wssConnexion')
|
||||
import {AccesRights} from './accesRights.js'
|
||||
import crypto from 'crypto'
|
||||
import {WssConnexion} from './wssConnexion.js'
|
||||
import session from 'express-session'
|
||||
import connectMySQL from 'express-mysql-session'
|
||||
|
||||
module.exports = class wssServer {
|
||||
export class wssServer {
|
||||
|
||||
constructor(configHelper, WSSServer, REDIScnx, debug) {
|
||||
this.debug = debug
|
||||
|
||||
Reference in New Issue
Block a user