37 lines
No EOL
1.1 KiB
TypeScript
37 lines
No EOL
1.1 KiB
TypeScript
import express from 'express';
|
|
import cors from 'cors';
|
|
import { executeCommand } from './broker.js';
|
|
|
|
const app = express();
|
|
const port = 8090;
|
|
|
|
app.use(cors());
|
|
// CORS aktivieren und den Origin explizit setzen
|
|
/*app.use(cors({
|
|
//origin: 'http://localhost:8080', // Erlaubt Anfragen vom Frontend (localhost:8080)
|
|
origin: 'http://127.0.0.1:8080',
|
|
//origin: 'https://192-168-197-2.c-one-infra.de',
|
|
methods: ['GET', 'POST', 'OPTIONS'], // Zulässige Methoden
|
|
allowedHeaders: ['Content-Type'], // Zulässige Header
|
|
credentials: true // Falls du Cookies oder Auth-Daten senden möchtest
|
|
}));
|
|
|
|
// Füge dies hinzu, um die OPTIONS-Anfragen korrekt zu behandeln
|
|
app.options('/api/command', cors()); // für eine bestimmte Route
|
|
|
|
// Verwende die Middleware, um POST-Body als JSON zu lesen
|
|
app.use(express.json());
|
|
|
|
app.use((req, res, next) => {
|
|
console.log('CORS headers set');
|
|
next();
|
|
});*/
|
|
|
|
app.post('/api/command', (req, res) => {
|
|
executeCommand();
|
|
res.status(200).send('Command executed\n');
|
|
});
|
|
|
|
app.listen(port, '0.0.0.0', () => {
|
|
console.log(`Server läuft auf http://0.0.0.0:${port}`);
|
|
}); |