add http-server part 7.9.9 CORS
All checks were successful
ci / build (push) Successful in 1m16s

This commit is contained in:
Christopher Hase 2025-04-11 14:33:55 +02:00
parent ce828cd5ef
commit 73063edd3f

View file

@ -9,7 +9,8 @@ const port = 8090;
// CORS aktivieren und den Origin explizit setzen // CORS aktivieren und den Origin explizit setzen
app.use(cors({ app.use(cors({
//origin: 'http://localhost:8080', // Erlaubt Anfragen vom Frontend (localhost:8080) //origin: 'http://localhost:8080', // Erlaubt Anfragen vom Frontend (localhost:8080)
origin: 'https://192-168-197-2.c-one-infra.de', origin: 'http://127.0.0.1:8080',
//origin: 'https://192-168-197-2.c-one-infra.de',
methods: ['GET', 'POST', 'OPTIONS'], // Zulässige Methoden methods: ['GET', 'POST', 'OPTIONS'], // Zulässige Methoden
allowedHeaders: ['Content-Type'], // Zulässige Header allowedHeaders: ['Content-Type'], // Zulässige Header
credentials: true // Falls du Cookies oder Auth-Daten senden möchtest credentials: true // Falls du Cookies oder Auth-Daten senden möchtest
@ -21,6 +22,11 @@ app.options('/api/command', cors()); // für eine bestimmte Route
// Verwende die Middleware, um POST-Body als JSON zu lesen // Verwende die Middleware, um POST-Body als JSON zu lesen
app.use(express.json()); app.use(express.json());
app.use((req, res, next) => {
console.log('CORS headers set');
next();
});
app.post('/api/command', (req, res) => { app.post('/api/command', (req, res) => {
executeCommand(); executeCommand();
res.status(200).send('Command executed\n'); res.status(200).send('Command executed\n');