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

This commit is contained in:
Christopher Hase 2025-04-11 12:34:35 +02:00
parent 36cdaea265
commit 131258aa86
2 changed files with 12 additions and 3 deletions

View file

@ -8,13 +8,16 @@ const port = 8090;
//CORS aktivieren //CORS aktivieren
app.use(cors()); app.use(cors());
// Verwende die Middleware, um POST-Body als JSON zu lesen
app.use(express.json());
/*app.use(cors({ /*app.use(cors({
origin: 'http://localhost:8080' origin: 'http://localhost:8080'
}));*/ }));*/
app.post('/api/command', (req, res) => { app.post('/api/command', (req, res) => {
executeCommand(); executeCommand();
res.status(200).send('Command executed'); res.status(200).send('Command executed\n');
}); });
app.listen(port, '0.0.0.0', () => { app.listen(port, '0.0.0.0', () => {

View file

@ -3,9 +3,15 @@ function handleClick(): void {
console.log("Der Button wurde geklickt!"); console.log("Der Button wurde geklickt!");
alert("Hallo von TypeScript!"); 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(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" }) /*fetch("/api/command", { method: "POST" })
.then(res => res.text()) .then(res => res.text())