2025-04-09 13:47:06 +00:00
|
|
|
import express from 'express';
|
2025-04-11 09:30:53 +00:00
|
|
|
import cors from 'cors';
|
2025-04-10 13:57:16 +00:00
|
|
|
import { executeCommand } from './broker.js';
|
2025-04-09 13:47:06 +00:00
|
|
|
|
|
|
|
const app = express();
|
2025-04-11 09:30:53 +00:00
|
|
|
const port = 8090;
|
2025-04-09 13:47:06 +00:00
|
|
|
|
2025-04-11 11:32:22 +00:00
|
|
|
//app.use(cors());
|
|
|
|
// CORS aktivieren und den Origin explizit setzen
|
|
|
|
app.use(cors({
|
2025-04-11 11:37:26 +00:00
|
|
|
//origin: 'http://localhost:8080', // Erlaubt Anfragen vom Frontend (localhost:8080)
|
|
|
|
origin: 'https://192-168-197-2.c-one-infra.de',
|
2025-04-11 11:32:22 +00:00
|
|
|
methods: ['GET', 'POST', 'OPTIONS'], // Zulässige Methoden
|
|
|
|
allowedHeaders: ['Content-Type'], // Zulässige Header
|
|
|
|
credentials: true // Falls du Cookies oder Auth-Daten senden möchtest
|
|
|
|
}));
|
2025-04-11 10:23:48 +00:00
|
|
|
|
2025-04-11 11:09:45 +00:00
|
|
|
// Füge dies hinzu, um die OPTIONS-Anfragen korrekt zu behandeln
|
2025-04-11 11:23:35 +00:00
|
|
|
app.options('/api/command', cors()); // für eine bestimmte Route
|
2025-04-11 11:09:45 +00:00
|
|
|
|
2025-04-11 10:34:35 +00:00
|
|
|
// Verwende die Middleware, um POST-Body als JSON zu lesen
|
|
|
|
app.use(express.json());
|
|
|
|
|
2025-04-09 13:47:06 +00:00
|
|
|
app.post('/api/command', (req, res) => {
|
|
|
|
executeCommand();
|
2025-04-11 10:34:35 +00:00
|
|
|
res.status(200).send('Command executed\n');
|
2025-04-09 13:47:06 +00:00
|
|
|
});
|
|
|
|
|
2025-04-09 14:51:26 +00:00
|
|
|
app.listen(port, '0.0.0.0', () => {
|
|
|
|
console.log(`Server läuft auf http://0.0.0.0:${port}`);
|
2025-04-10 06:57:08 +00:00
|
|
|
});
|