Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e87a3fb0d |
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Zahlen raten</title>
|
||||
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css">
|
||||
<link rel="stylesheet" href="/bootstrap/css/bootstrap.css">
|
||||
<link rel="stylesheet" href="style/styles.css">
|
||||
<script src="src/client.js"></script>
|
||||
</head>
|
||||
@ -6,17 +6,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const guessInput = document.getElementById('guessInput') as HTMLInputElement;
|
||||
const guessValue = guessInput.value;
|
||||
|
||||
if (guessValue === '') {
|
||||
displayResult('Please enter a valid number!');
|
||||
return;
|
||||
}
|
||||
|
||||
// Hier sendest du die Anfrage an den Server
|
||||
fetch('http://localhost:8080/guess', { // Beachte die richtige Serveradresse
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ guess: guessValue }),
|
||||
fetch(`http://localhost:8080/guess/${guessValue}`, { // Beachte die richtige Serveradresse
|
||||
method: 'GET'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
// Hier wird die Antwort des Servers in einem sichtbaren Bereich angezeigt
|
||||
console.log(data)
|
||||
displayResult(data.answer);
|
||||
})
|
||||
.catch(error => {
|
||||
@ -10,15 +10,11 @@ app.use(express.json());
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
let basedir: string = __dirname + "../../client";
|
||||
let basedir: string = __dirname + "/../client";
|
||||
app.use("/", express.static(basedir + "/"));
|
||||
app.use("/bootstrap", express.static(basedir + "/node_modules/bootstrap/dist/"));
|
||||
|
||||
app.use("/bootstrap", express.static(basedir + "/../node_modules/bootstrap/dist/"));
|
||||
let ranNum: number;
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile(__dirname + 'Aufgabenblatt 3/index.html');
|
||||
});
|
||||
app.listen(port, () => {
|
||||
console.log(`Server gestartet auf http://localhost:${port}/`);
|
||||
ranNum = random(1, 10);
|
||||
@ -55,7 +51,7 @@ app.post('/reset', (req, res) => {
|
||||
const min: number = Number(req.body.min);
|
||||
const max: number = Number(req.body.max);
|
||||
if (Number.isNaN(min || Number.isNaN(max) || min > max || min <= 0 || max <= 0)) {
|
||||
return res.status(400).send({
|
||||
return res.status(200).send({
|
||||
message: 'Invalid input'
|
||||
})
|
||||
}
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
"module": "ESNext",
|
||||
"target": "es6",
|
||||
"sourceMap": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user