diff options
author | Mark Powers <markppowers0@gmail.com> | 2020-04-13 15:30:16 -0500 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2020-04-13 15:30:16 -0500 |
commit | 84dca4c6dc0cff9a417ebd0d8f7de06acafa6725 (patch) | |
tree | 14eaebd6733ea6ef4a8777b23b9fb233ee1e3ac8 /src/server.js | |
parent | afc1a847f4e93c9fb0ec718286089d409030c95a (diff) |
Update documentation
Diffstat (limited to 'src/server.js')
-rw-r--r-- | src/server.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/server.js b/src/server.js index 07fa430..c159666 100644 --- a/src/server.js +++ b/src/server.js @@ -12,18 +12,25 @@ function listen(port) { server.listen(port, () => console.info(`Listening on port ${port}!`)); } +// Load a game and its routes function load(gamePath, models, jwtFunctions, database) { const game = require(gamePath); game.setUpRoutes(server, models, jwtFunctions, database); } function setUpRoutes(models, jwtFunctions, database) { + // Route logger server.use(function (req, res, next) { console.debug(new Date(), req.method, req.originalUrl); next() }) + // Static files server.get('/', (req, res) => res.sendFile(__dirname + "/index.html")) + server.get('/highscore.js', (req, res) => res.sendFile(__dirname + "/highscores.js")) + server.get('/highscores', (req, res) => res.sendFile(__dirname + "/scores.html")) + + // Sets a score server.get('/setScore', async (req, res, next) => { var results = await models.scores.findAll({ where: { uuid: { [Op.eq]: req.query.uuid } } @@ -40,6 +47,8 @@ function setUpRoutes(models, jwtFunctions, database) { }) res.status(200).send("score saved") }) + + // Gets all scores, grouped by game server.get('/scores', async (req, res, next) => { var games = await database.query(`SELECT DISTINCT game FROM scores`, { type: database.QueryTypes.SELECT }); var scoresByGames = {} @@ -48,8 +57,8 @@ function setUpRoutes(models, jwtFunctions, database) { }; res.status(200).send(scoresByGames); }) - server.get('/highscore.js', (req, res) => res.sendFile(__dirname + "/highscores.js")) - server.get('/highscores', (req, res) => res.sendFile(__dirname + "/scores.html")) + + // Gets a unique ID server.get('/uuid', async (req, res) => { var uuid; while (true) { |