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