Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade node modules #49

Merged
merged 8 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ RUN elm make Main.elm --output=client/index.js

FROM base AS release
ENV LEGO_PATH=/lego-files

COPY --from=dependencies /home/node/app/node_modules node_modules
COPY --from=elm-build /home/node/app/elm-client/client/ client
COPY package.json package.json
COPY server server
COPY server.sh server.sh
COPY healthcheck.sh healthcheck.sh
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "swarm-dash",
"name": "swarm-dashboard",
"type": "module",
"version": "1.0.0",
"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 'node:fs';
import { request, createServer as httpCreateServer } from 'http';
import { createServer as httpsCreateServer } from 'https';
import { createHash } from 'crypto';
import parsePrometheusTextFormat from 'parse-prometheus-text-format';

import WebSocket, { WebSocketServer } 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 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 @@ -513,7 +513,7 @@ const addTaskMetricsToData = (data, lastRunningTasksMetrics) => {

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

listener.send(JSON.stringify(data, null, 2));
});
Expand Down Expand Up @@ -546,7 +546,7 @@ let listeners = [];
let lastData = {};
let lastSha = '';

users = {};
let users = {};
users[username] = password;
const basicAuthConfig = () => basicAuth({
users: users,
Expand All @@ -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 = httpsCreateServer(credentials);
httpsServer.on('request', app);
const wsServer = new ws.Server({
const wsServer = new WebSocketServer({
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 = httpCreateServer();
httpServer.on('request', app);
const wsServer = new ws.Server({
const wsServer = new WebSocketServer({
path: pathPrefix + '/stream',
server: httpServer,
});
Expand Down
Loading
Loading