From 8fd7bfa6cf2c2390b18870ffc5e16f9781a183cd Mon Sep 17 00:00:00 2001 From: biglyderv Date: Sun, 20 Apr 2025 22:44:35 -0400 Subject: [PATCH] fix cors wonkiness --- index.js | 8 ++++---- package-lock.json | 23 +++++++++++++++++++++++ package.json | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 4b72a9f..3122a49 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,13 @@ import { spawn } from "node:child_process"; import { mkdir } from 'node:fs/promises'; import { createHash } from "node:crypto"; import express from "express"; +import cors from "cors"; let sessions = {}; let channels = {}; const app = express(); +app.use(cors()) app.use(express.json()) app.set('trust proxy', true) @@ -35,7 +37,7 @@ app.post('/', async function (req, res) { if (channels[id].headersSent) return; try { - channels[id].send(str).header('access-allow-control-origin', '*') + channels[id].send(str) } catch (err) { } } }); @@ -51,7 +53,7 @@ app.post('/', async function (req, res) { if (fsession != channels[id]) return; if (channels[id].headersSent) return; try { - channels[id].send('Input is possibly malformed.').header('access-allow-control-origin', '*') + channels[id].send('Input is possibly malformed.') } catch (err) { } @@ -65,10 +67,8 @@ app.post('/', async function (req, res) { msg = `/${msg.slice(1)}`; } - setTimeout(async function () { sessions[id].lastBusy = new Date(); sessions[id].stdin.write(msg + '\n'); - }, 100); }); app.listen(process.env.port || 3007) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 66e832c..bd26df5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "packages": { "": { "dependencies": { + "cors": "^2.8.5", "express": "^5.1.0" } }, @@ -118,6 +119,19 @@ "node": ">=6.6.0" } }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/debug": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", @@ -492,6 +506,15 @@ "node": ">= 0.6" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", diff --git a/package.json b/package.json index 2eb537b..8327855 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "type": "module", "dependencies": { + "cors": "^2.8.5", "express": "^5.1.0" } }