diff --git a/backend.js b/backend.js index c561183..14b64a8 100644 --- a/backend.js +++ b/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 app.get('/api/user/:sessionId', (req,res) => { 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 app.put('/api/ready/:sessionId', (req,res) => { diff --git a/game/game.html b/game/game.html new file mode 100644 index 0000000..9ec2dde --- /dev/null +++ b/game/game.html @@ -0,0 +1,11 @@ + + + + + + game + + + + + \ No newline at end of file diff --git a/game/game.js b/game/game.js new file mode 100644 index 0000000..e69de29 diff --git a/game/style.css b/game/style.css new file mode 100644 index 0000000..e69de29 diff --git a/imposter.db b/imposter.db index dd82e06..785856b 100644 Binary files a/imposter.db and b/imposter.db differ diff --git a/index.html b/index.html index e8968db..04be76f 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,11 @@ +
+ + + +
\ No newline at end of file diff --git a/index.js b/index.js index 888fe0a..719ef8b 100644 --- a/index.js +++ b/index.js @@ -9,3 +9,20 @@ function re_direct () { 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) + }); +}