diff --git a/backend/server.ts b/backend/server.ts index 3d58828..29d9c7e 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -8,13 +8,16 @@ const port = 8090; //CORS aktivieren app.use(cors()); +// Verwende die Middleware, um POST-Body als JSON zu lesen +app.use(express.json()); + /*app.use(cors({ origin: 'http://localhost:8080' }));*/ app.post('/api/command', (req, res) => { executeCommand(); - res.status(200).send('Command executed'); + res.status(200).send('Command executed\n'); }); app.listen(port, '0.0.0.0', () => { diff --git a/frontend/event.ts b/frontend/event.ts index 21b0409..d01f4e2 100644 --- a/frontend/event.ts +++ b/frontend/event.ts @@ -3,9 +3,15 @@ function handleClick(): void { console.log("Der Button wurde geklickt!"); alert("Hallo von TypeScript!"); - fetch("http://localhost:8090/api/command", { method: "POST" }) + fetch("http://localhost:8090/api/command", { + method: "POST", + headers: { + "Content-Type": "application/json", // Füge dies hinzu, wenn du JSON sendest + } + }) .then(res => res.text()) - .then(text => console.log("Server sagt:", text)); + .then(text => console.log("Server sagt:", text)) + .catch(error => console.error("Fehler:", error)); /*fetch("/api/command", { method: "POST" }) .then(res => res.text())