1
0

feat: Allow cors
All checks were successful
Remote Deploy / deploy (push) Successful in 6s

This commit is contained in:
2026-01-23 18:13:45 +01:00
parent c34f4ee1d1
commit 1013a3ba15
4 changed files with 37 additions and 1 deletions

27
package-lock.json generated
View File

@@ -12,6 +12,7 @@
"body-parser": "^2.2.0",
"cheerio": "^1.1.2",
"concurrently": "^9.2.0",
"cors": "^2.8.6",
"dotenv": "^17.2.3",
"exceljs": "^4.4.0",
"express": "^5.1.0",
@@ -809,6 +810,23 @@
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
"license": "MIT"
},
"node_modules/cors": {
"version": "2.8.6",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz",
"integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==",
"license": "MIT",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/cosmiconfig": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz",
@@ -2152,6 +2170,15 @@
"url": "https://github.com/fb55/nth-check?sponsor=1"
}
},
"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

@@ -16,6 +16,7 @@
"body-parser": "^2.2.0",
"cheerio": "^1.1.2",
"concurrently": "^9.2.0",
"cors": "^2.8.6",
"dotenv": "^17.2.3",
"exceljs": "^4.4.0",
"express": "^5.1.0",

View File

@@ -19,7 +19,7 @@ globalThis.File = class File {};
export default async function parseTeachers() {
const url = "https://spsejecna.cz/ucitel";
const response = await fetch(url);
const data = await response.text(); // fetch needs .text() to get HTML
const data = await response.text();
const $ = cheerio.load(data);
const map = {};

View File

@@ -18,6 +18,7 @@ const app = express();
import fs from "fs/promises";
import { getCurrentInterval } from "./scheduleRules.js";
import bodyParser from "body-parser";
import cors from "cors";
const VERSIONS = ["v1", "v2"];
const PORT = process.env.PORT || 3000;
@@ -26,6 +27,13 @@ globalThis.File = class File {};
app.use(bodyParser.json());
app.use(cors({
origin: "*",
methods: ["GET", "POST", "OPTIONS"],
allowedHeaders: ["Content-Type"],
}));
app.options("*", cors());
app.get('/', async (req, res) => {
const userAgent = req.headers['user-agent'] || '';
const isBrowser = /Mozilla|Chrome|Firefox|Safari|Edg/.test(userAgent);