fix cors wonkiness

This commit is contained in:
biglyderv 2025-04-20 22:44:35 -04:00
parent 46906f8900
commit 8fd7bfa6cf
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
3 changed files with 28 additions and 4 deletions

View file

@ -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)

23
package-lock.json generated
View file

@ -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",

View file

@ -1,6 +1,7 @@
{
"type": "module",
"dependencies": {
"cors": "^2.8.5",
"express": "^5.1.0"
}
}