From 0b2d27d70ec47b17bc154dc9e472bd103f5188f3 Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 13 Jul 2025 20:50:34 +0200 Subject: [PATCH] Added cors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added cors to use an alternative frontend (vite). To use the api and receive the data. (cors() with no options is a wildcard configuration — it allows requests from any origin (Access-Control-Allow-Origin: *) and accepts standard headers like Authorization) --- index.js | 7 ++++++- package.json | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f871165..2cfaaef 100755 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ const crypto = require('crypto'); const os = require('os'); const { spawn, execSync } = require('child_process'); const express = require('express'); +const cors = require('cors'); const packageJson = require('./package.json'); const fetch = require('node-fetch'); // Add node-fetch for API validation const WebSocket = require('ws'); // Add WebSocket for real-time container communication @@ -1302,7 +1303,11 @@ async function startWebGUI(options = {}) { // Create Express apps const guiApp = express(); const metricsApp = express(); - + + // Add cors middleware to both apps + guiApp.use(cors()); + metricsApp.use(cors()); + // Add authentication middleware to GUI app guiApp.use(authenticateRequest); diff --git a/package.json b/package.json index cf8a95d..558c662 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "dependencies": { "chalk": "^4.1.2", "commander": "^8.3.0", + "cors": "^2.8.5", "inquirer": "^7.3.3", "express": "^4.18.2", "node-fetch": "^2.6.7",