Skip to content

Commit

Permalink
upgrade node modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsenasm committed Jan 1, 2025
1 parent c5b07db commit 9d65c81
Show file tree
Hide file tree
Showing 3 changed files with 492 additions and 676 deletions.
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"express": "^4.19.2",
"express": "5.0.1",
"express-basic-auth": "^1.2.1",
"moment": "^2.29.4",
"parse-prometheus-text-format": "^1.1.1",
"ramda": "^0.24.1",
"uuid": "^9.0.1",
"ramda": "0.30.1",
"uuid": "11.0.3",
"ws": "^8.17.1"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^8.53.0",
"prettier": "^1.5.3"
"babel-eslint-parser": "7.13.10",
"eslint": "9.17.0"
}
}
56 changes: 28 additions & 28 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var fs = require('fs');
var http = require('http');
var https = require('https');
const { createHash } = require('crypto');
const parsePrometheusTextFormat = require('parse-prometheus-text-format');

const ws = require('ws');
const express = require('express');
const basicAuth = require('express-basic-auth')
const { v4: uuidv4 } = require('uuid');
const url = require('url');
const { sortBy, prop } = require('ramda');
const moment = require('moment');
import { readFileSync, watchFile } from 'fs';
import { request, createServer } from 'http';
import { createServer as _createServer } from 'https';
import { createHash } from 'crypto';
import parsePrometheusTextFormat from 'parse-prometheus-text-format';

import { OPEN, Server } from 'ws';
import express, { Router } from 'express';
import basicAuth from 'express-basic-auth';
import { v4 as uuidv4 } from 'uuid';
import { parse } from 'url';
import { sortBy, prop } from 'ramda';
import moment, { duration } from 'moment';

const port = process.env.PORT || 8080;
const realm = process.env.AUTHENTICATION_REALM || "KuW2i9GdLIkql";
Expand Down Expand Up @@ -71,7 +71,7 @@ const dockerAPIRequest = path => {
return new Promise((res, rej) => {
let buffer = '';

const r = http.request({ ...dockerRequestBaseOptions, path }, response => {
const r = request({ ...dockerRequestBaseOptions, path }, response => {
response.on('data', chunk => (buffer = buffer + chunk));
response.on('end', () => res(buffer));
});
Expand Down Expand Up @@ -101,7 +101,7 @@ const metricRequest = (url) => {
return new Promise((res, rej) => {
let buffer = '';

const r = http.request(url, response => {
const r = request(url, response => {
response.on('data', chunk => (buffer = buffer + chunk));
response.on('end', () => res(buffer));
});
Expand Down Expand Up @@ -224,7 +224,7 @@ const parseAndRedactDockerData = data => {
const lastTimestamp = moment(baseTask["Status"]["Timestamp"]);
let timestateInfo = undefined;
if (showTaskTimestamp) {
timestateInfo = moment.duration(lastTimestamp - now).humanize(true);
timestateInfo = duration(lastTimestamp - now).humanize(true);
}
let task = {
"ID": baseTask["ID"],
Expand Down Expand Up @@ -513,7 +513,7 @@ const addTaskMetricsToData = (data, lastRunningTasksMetrics) => {

const publish = (listeners, data) => {
listeners.forEach(listener => {
if (listener.readyState !== ws.OPEN) return;
if (listener.readyState !== OPEN) return;

listener.send(JSON.stringify(data, null, 2));
});
Expand Down Expand Up @@ -556,7 +556,7 @@ const basicAuthConfig = () => basicAuth({
const tokenStore = new Set();

const app = express();
const router = express.Router();
const router = Router();
router.use(express.static('client'));
router.get('/_health', (req, res) => res.end());
if (enableAuthentication) {
Expand Down Expand Up @@ -636,7 +636,7 @@ function onWSConnection(ws, req) {
let params = undefined;
let authToken = undefined;
if (req)
params = url.parse(req.url, true).query; // { authToken: 'ajsdhakjsdhak' } for 'ws://localhost:1234/?authToken=ajsdhakjsdhak'
params = parse(req.url, true).query; // { authToken: 'ajsdhakjsdhak' } for 'ws://localhost:1234/?authToken=ajsdhakjsdhak'
if (params)
authToken = params.authToken;

Expand Down Expand Up @@ -664,34 +664,34 @@ function onWSConnection(ws, req) {
if (enableHTTPS) {
const privateKeyPath = legoPath + '/certificates/' + httpsHostname + '.key';
const certificatePath = legoPath + '/certificates/' + httpsHostname + '.crt';
const privateKey = fs.readFileSync(privateKeyPath, 'utf8');
const certificate = fs.readFileSync(certificatePath, 'utf8');
const privateKey = readFileSync(privateKeyPath, 'utf8');
const certificate = readFileSync(certificatePath, 'utf8');
const credentials = { key: privateKey, cert: certificate }
const httpsServer = https.createServer(credentials);
const httpsServer = _createServer(credentials);
httpsServer.on('request', app);
const wsServer = new ws.Server({
const wsServer = new Server({
path: pathPrefix + '/stream',
server: httpsServer,
});
wsServer.on('connection', onWSConnection);
httpsServer.listen(port, () => {
console.log(`HTTPS server listening on ${port}`); // eslint-disable-line no-console
});
fs.watchFile(certificatePath, { interval: 1000 }, () => {
watchFile(certificatePath, { interval: 1000 }, () => {
try {
console.log('Reloading TLS certificate');
const privateKey = fs.readFileSync(privateKeyPath, 'utf8');
const certificate = fs.readFileSync(certificatePath, 'utf8');
const privateKey = readFileSync(privateKeyPath, 'utf8');
const certificate = readFileSync(certificatePath, 'utf8');
const credentials = { key: privateKey, cert: certificate }
httpsServer.setSecureContext(credentials);
} catch (e) {
console.log(e)
}
});
} else {
const httpServer = http.createServer();
const httpServer = createServer();
httpServer.on('request', app);
const wsServer = new ws.Server({
const wsServer = new Server({
path: pathPrefix + '/stream',
server: httpServer,
});
Expand Down
Loading

0 comments on commit 9d65c81

Please sign in to comment.