This commit is contained in:
parent
36cdaea265
commit
131258aa86
2 changed files with 12 additions and 3 deletions
|
@ -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', () => {
|
||||||
|
|
|
@ -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())
|
||||||
|
|
Loading…
Reference in a new issue