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)