hinzufügen von wörtern
This commit is contained in:
32
backend.js
32
backend.js
@ -45,6 +45,12 @@ app.get('/:sessionId/:username', (req, res) => {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.get('/:sessionId/:username/game', (req, res) => {
|
||||||
|
const {sessionId, username} = req.params;
|
||||||
|
|
||||||
|
res.sendFile(join (__dirname, 'game', 'game.html'));
|
||||||
|
})
|
||||||
|
|
||||||
//liste an user zurückgeben
|
//liste an user zurückgeben
|
||||||
app.get('/api/user/:sessionId', (req,res) => {
|
app.get('/api/user/:sessionId', (req,res) => {
|
||||||
const {sessionId} = req.params;
|
const {sessionId} = req.params;
|
||||||
@ -60,6 +66,32 @@ app.get('/api/user/:sessionId', (req,res) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
app.put(`/api/words/add`, (req,res) => {
|
||||||
|
const payload = req.body;
|
||||||
|
|
||||||
|
console.log(payload.word, payload.imposterWord)
|
||||||
|
|
||||||
|
db.serialize(() => {
|
||||||
|
db.run(`CREATE TABLE IF NOT EXISTS words (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
word TEXT NOT NULL,
|
||||||
|
imposterWord TEXT NOT NULL
|
||||||
|
)`);
|
||||||
|
|
||||||
|
db.run(`INSERT INTO words (word, imposterWord) VALUES (?, ?)`,
|
||||||
|
[payload.word, payload.imposterWord],
|
||||||
|
function (err){
|
||||||
|
if (err) {
|
||||||
|
console.error('inserted words error:', err);
|
||||||
|
return res.status(500).json({error: err.message});
|
||||||
|
}
|
||||||
|
res.status(201).json({id: this.lastID})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//ready status updaten
|
//ready status updaten
|
||||||
app.put('/api/ready/:sessionId', (req,res) => {
|
app.put('/api/ready/:sessionId', (req,res) => {
|
||||||
|
|||||||
11
game/game.html
Normal file
11
game/game.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>game</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
0
game/game.js
Normal file
0
game/game.js
Normal file
0
game/style.css
Normal file
0
game/style.css
Normal file
BIN
imposter.db
BIN
imposter.db
Binary file not shown.
@ -12,6 +12,11 @@
|
|||||||
<input id="session_id" placeholder = "session_id">
|
<input id="session_id" placeholder = "session_id">
|
||||||
<button onclick="re_direct()">send</button>
|
<button onclick="re_direct()">send</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<input id="word" placeholder="word">
|
||||||
|
<input id="imposterWord" placeholder="Imposter Wort">
|
||||||
|
<button onclick="addWord()">Wörter hinzufügen</button>
|
||||||
|
</div>
|
||||||
<script src="index.js"></script>
|
<script src="index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
17
index.js
17
index.js
@ -9,3 +9,20 @@ function re_direct () {
|
|||||||
window.location.href = `/${encodedSession}/${encodedUser}`;
|
window.location.href = `/${encodedSession}/${encodedUser}`;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function addWord() {
|
||||||
|
const word = document.getElementById('word').value.trim();
|
||||||
|
const imposterWord = document.getElementById('imposterWord').value.trim();
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
word: word,
|
||||||
|
imposterWord: imposterWord,
|
||||||
|
}
|
||||||
|
const res = await fetch (`/api/words/add`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user