First commit
This commit is contained in:
BIN
backend/.DS_Store
vendored
Normal file
BIN
backend/.DS_Store
vendored
Normal file
Binary file not shown.
8
backend/Dockerfile
Normal file
8
backend/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM node:18
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN npm install
|
||||
|
||||
EXPOSE 3000
|
||||
CMD ["node", "server.js"]
|
||||
5634
backend/c_condensed.json
Normal file
5634
backend/c_condensed.json
Normal file
File diff suppressed because it is too large
Load Diff
6529
backend/d_condensed.json
Executable file
6529
backend/d_condensed.json
Executable file
File diff suppressed because it is too large
Load Diff
18
backend/package.json
Normal file
18
backend/package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "trainer2",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"type": "commonjs",
|
||||
"dependencies": {
|
||||
"cookie-parser": "^1.4.7",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^5.1.0"
|
||||
}
|
||||
}
|
||||
32
backend/server.js
Normal file
32
backend/server.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const express = require("express");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const cors = require("cors");
|
||||
const cookieParser = require("cookie-parser");
|
||||
|
||||
const app = express();
|
||||
const PORT = 3000;
|
||||
|
||||
//app.use(cors({ origin: "https://schiri.marc-wieland.de", credentials: true }));
|
||||
app.use(cookieParser());
|
||||
app.use(express.json());
|
||||
|
||||
|
||||
app.get("/api/questions/:mode", (req, res) => {
|
||||
const mode = req.params.mode?.toLowerCase();
|
||||
if (!["d", "c"].includes(mode)) {
|
||||
return res.status(400).json({ error: "Ungültiger Modus. Nur 'd' oder 'c' erlaubt." });
|
||||
}
|
||||
|
||||
const filePath = path.join(__dirname, `${mode}_condensed.json`);
|
||||
try {
|
||||
const data = fs.readFileSync(filePath, "utf8");
|
||||
res.json(JSON.parse(data));
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: "Fehler beim Laden der Fragen." });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`📡 Backend läuft auf http://localhost:${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user