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){
|
constructor(config, debug){
|
||||||
this.debug = 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.
|
/* Creates (predictable) peer-to-peer chan if necessary, or check for lobby existence, then subscribe to it.
|
||||||
Request:
|
Request:
|
||||||
|
|||||||
+15
-7
@@ -1,9 +1,17 @@
|
|||||||
module.exports.methods = {}
|
import { methods as utilities } from './utilities.js'
|
||||||
Object.assign(module.exports.methods, require('./utilities').methods )
|
import { methods as pubSub } from './pubSub.js'
|
||||||
Object.assign(module.exports.methods, require('./pubSub').methods )
|
import { methods as store } from './store.js'
|
||||||
Object.assign(module.exports.methods, require('./store').methods )
|
import { methods as sessions } from './sessions.js'
|
||||||
Object.assign(module.exports.methods, require('./sessions').methods )
|
import { methods as notifications } from './notifications.js'
|
||||||
Object.assign(module.exports.methods, require('./notifications').methods )
|
import { methods as chat } from './chat.js'
|
||||||
Object.assign(module.exports.methods, require('./chat').methods )
|
|
||||||
|
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){
|
async action_NOTIFS(action, payload, reqid){
|
||||||
let reply = {
|
let reply = {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
module.exports.methods = {
|
export const methods = {
|
||||||
/* Request:
|
/* Request:
|
||||||
{
|
{
|
||||||
"action": "SUB",
|
"action": "SUB",
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
module.exports.methods = {
|
export const methods = {
|
||||||
|
|
||||||
/* Request payload : null
|
/* Request payload : null
|
||||||
Reply:
|
Reply:
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
module.exports.methods = {
|
export const methods = {
|
||||||
|
|
||||||
/* Request:
|
/* Request:
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports.methods = {
|
export const methods = {
|
||||||
|
|
||||||
/* Request:
|
/* Request:
|
||||||
{
|
{
|
||||||
|
|||||||
+9
-8
@@ -1,9 +1,8 @@
|
|||||||
const Ajv = require("ajv")
|
import Ajv from 'ajv'
|
||||||
const confSchema = require('./configSchema.json')
|
import confSchema from './configSchema.json' with { type: 'json' }
|
||||||
|
import { pathToFileURL } from 'url'
|
||||||
|
|
||||||
let DynamoDBClient, GetItemCommand, marshall, unmarshall
|
export class configHelper {
|
||||||
|
|
||||||
module.exports = class configHelper {
|
|
||||||
|
|
||||||
constructor(options){
|
constructor(options){
|
||||||
this.config = {}
|
this.config = {}
|
||||||
@@ -24,7 +23,10 @@ module.exports = class configHelper {
|
|||||||
|
|
||||||
async fetchConfigFile(){
|
async fetchConfigFile(){
|
||||||
let curConfig = this.config
|
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)
|
if(this.isValidConfig(this.config)) return(this.config)
|
||||||
console.error(this.isValidConfig.errors)
|
console.error(this.isValidConfig.errors)
|
||||||
//revert if invalid conf
|
//revert if invalid conf
|
||||||
@@ -37,9 +39,8 @@ module.exports = class configHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async refreshAccessRightsFile(){
|
async refreshAccessRightsFile(){
|
||||||
delete require.cache[require.resolve(this.localfile)]
|
|
||||||
let tmp
|
let tmp
|
||||||
try { tmp = require(this.localfile) }
|
try { tmp = import(`${this.localfile}?update=${Date.now()}`, { assert: { type: 'json' } }) }
|
||||||
catch(err) {
|
catch(err) {
|
||||||
console.error('Error Reloading config !! (bad json?) => Keeping current accessRights !')
|
console.error('Error Reloading config !! (bad json?) => Keeping current accessRights !')
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"version": "3.4.6",
|
"version": "3.4.6",
|
||||||
"description": "Websocket-Redis Message Bus Gateway",
|
"description": "Websocket-Redis Message Bus Gateway",
|
||||||
"main": "wssGateway.js",
|
"main": "wssGateway.js",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest --verbose"
|
"test": "jest --verbose"
|
||||||
},
|
},
|
||||||
@@ -15,6 +16,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ajv": "^8.12.0",
|
"ajv": "^8.12.0",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
|
"express-mysql-session": "^3.0.3",
|
||||||
|
"express-session": "^1.18.2",
|
||||||
"pm2": "^6.0.10",
|
"pm2": "^6.0.10",
|
||||||
"redis": "^4.3.0",
|
"redis": "^4.3.0",
|
||||||
"urldecode": "^1.0.1",
|
"urldecode": "^1.0.1",
|
||||||
|
|||||||
+2
-3
@@ -1,6 +1,5 @@
|
|||||||
const redis = require('redis');
|
import redis from 'redis'
|
||||||
|
export class RedisConnexion {
|
||||||
module.exports = class RedisConnexion {
|
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const AccesRights = require('../accesRights')
|
import {AccesRights} from '../accesRights'
|
||||||
let accessRights = new AccesRights({
|
let accessRights = new AccesRights({
|
||||||
"accessRights": [
|
"accessRights": [
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-4
@@ -1,10 +1,10 @@
|
|||||||
const crypto = require('crypto')
|
import crypto from 'crypto'
|
||||||
const gatewayActions = require('./actions')
|
import { gatewayActions } from './actions/index.js'
|
||||||
|
|
||||||
module.exports = class WssConnexion {
|
export class WssConnexion {
|
||||||
|
|
||||||
constructor(options){
|
constructor(options){
|
||||||
Object.assign(this, gatewayActions.methods)
|
Object.assign(this, gatewayActions)
|
||||||
|
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
this.socket = options.socket;
|
this.socket = options.socket;
|
||||||
|
|||||||
+13
-12
@@ -1,13 +1,14 @@
|
|||||||
const yargs = require('yargs')
|
import yargs from 'yargs/yargs'
|
||||||
const ws = require('ws')
|
import { hideBin } from 'yargs/helpers'
|
||||||
const fs = require('fs')
|
|
||||||
const RedisConnexion = require('./redisConnexion')
|
|
||||||
const urlparser = require('url');
|
|
||||||
const wssServer = require('./wssServer')
|
|
||||||
const configHelper = require('./configHelper')
|
|
||||||
|
|
||||||
|
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({
|
.options({
|
||||||
'argv.debug': {
|
'argv.debug': {
|
||||||
description: 'shows debug info',
|
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)) {
|
if((!wssGatewayConfig) || (Object.keys(wssGatewayConfig).length<4)) {
|
||||||
console.error('Cannot get a valid configuration ! Aaarrghhh...')
|
console.error('Cannot get a valid configuration ! Aaarrghhh...')
|
||||||
process.exit()
|
process.exit()
|
||||||
}
|
}
|
||||||
let httpLib
|
let httpLib
|
||||||
if(wssGatewayConfig.server.unsecure) httpLib = require('http')
|
if(wssGatewayConfig.server.unsecure) httpLib = await import('http')
|
||||||
else httpLib = require('https')
|
else httpLib = await import('https')
|
||||||
|
|
||||||
|
|
||||||
/////////////////////// Create & Start servers \\\\\\\\\\\\\\\\\\\\\\
|
/////////////////////// Create & Start servers \\\\\\\\\\\\\\\\\\\\\\
|
||||||
@@ -91,7 +92,7 @@ cfgh.fetchConfig().then( wssGatewayConfig => {
|
|||||||
wssServerOptions['key'] = fs.readFileSync(wssGatewayConfig.server.certKeyFile)
|
wssServerOptions['key'] = fs.readFileSync(wssGatewayConfig.server.certKeyFile)
|
||||||
wssServerOptions['cert'] = fs.readFileSync(wssGatewayConfig.server.certFile)
|
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}`)
|
console.log(`WS${wssGatewayConfig.server.unsecure ? '': 'S'} server created for ${wssGatewayConfig.server.listenHost}:${wssGatewayConfig.server.listenPort}`)
|
||||||
|
|
||||||
startRedis(wssGatewayConfig).then((rediscnx) => {
|
startRedis(wssGatewayConfig).then((rediscnx) => {
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
"serviceName": "wssGateway",
|
"serviceName": "wssGateway",
|
||||||
"server": {
|
"server": {
|
||||||
"listenHost": "0.0.0.0",
|
"listenHost": "0.0.0.0",
|
||||||
"listenPort": 4443,
|
"listenPort": 3999,
|
||||||
"listenPath": "/msgbus",
|
"listenPath": "/msgbus",
|
||||||
"keepAliveInterval": "30",
|
"keepAliveInterval": "30",
|
||||||
"keepAliveTimeout": "5",
|
"keepAliveTimeout": "5",
|
||||||
"certFile": "/etc/letsencrypt/live/eismea.internike.com/fullchain.pem",
|
"certFile": "/etc/letsencrypt/live/42.internike.com/fullchain.pem",
|
||||||
"certKeyFile": "/etc/letsencrypt/live/eismea.internike.com/privkey.pem",
|
"certKeyFile": "/etc/letsencrypt/live/42.internike.com/privkey.pem",
|
||||||
"challengeExpiration": 20,
|
"challengeExpiration": 20,
|
||||||
"unsecure": false,
|
"unsecure": false,
|
||||||
"healthCheckPath": "/status",
|
"healthCheckPath": "/status",
|
||||||
|
|||||||
+6
-4
@@ -1,8 +1,10 @@
|
|||||||
const AccesRights = require('./accesRights')
|
import {AccesRights} from './accesRights.js'
|
||||||
const crypto = require('crypto')
|
import crypto from 'crypto'
|
||||||
const WssConnexion = require('./wssConnexion')
|
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) {
|
constructor(configHelper, WSSServer, REDIScnx, debug) {
|
||||||
this.debug = debug
|
this.debug = debug
|
||||||
|
|||||||
Reference in New Issue
Block a user