From: Carl Worth Date: Sun, 26 Apr 2020 22:25:14 +0000 (-0700) Subject: Make the server store a list of players X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=382208c4df224f4d917476d83ea728f369d58784;p=lmno-server Make the server store a list of players Expecting both "name" and "character" on each post to the /register API. Also add a /players API to list the players registered so far. --- diff --git a/server.js b/server.js index 46eda0a..c62a9ea 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,8 @@ const body_parser = require("body-parser"); const app = express(); +const players = []; + app.use(body_parser.urlencoded({ extended: false })); app.use(body_parser.json()); @@ -10,8 +12,15 @@ app.get('/', function (req, res) { res.send('Hello World!'); }); +app.get('/players', function (req, res) { + res.send(players); +}); + + app.post('/register', function (req, res) { - console.log(req.body); + players.push({name: req.body.name, + character: req.body.character}); + res.send(); }); app.listen(3000, function () {