-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
25 lines (24 loc) · 845 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const express = require('express');
const cookieParser = require('cookie-parser');
const app = express();
const PORT = 3000;
const game = require('./game');
app.use(express.static('./public'));
app.use(express.urlencoded({extended: false}));
app.use(cookieParser());
app.get('/', (req, res) => {
let {uuid, userPage} = game.loadPage(req);
res.cookie("gamestate", {uuid});
res.send(userPage)
});
app.post('/sendGuess', express.urlencoded({ extended: false }), (req, res) => {
let uuid = game.gameLogic(req);
res.cookie("gamestate", {uuid});
res.redirect('/');
});
app.post('/newGame', express.urlencoded({ extended: false}), (req, res) => {
let uuid = game.generateNewGame();
res.cookie("gamestate", {uuid});
res.redirect('/');
});
app.listen(PORT, () => console.log(`Listening on http://localhost:${PORT}`));