From 382208c4df224f4d917476d83ea728f369d58784 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sun, 26 Apr 2020 15:25:14 -0700 Subject: [PATCH] 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. --- server.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 () { -- 2.43.0