]> git.cworth.org Git - empires-server/commitdiff
Make the server store a list of players
authorCarl Worth <cworth@cworth.org>
Sun, 26 Apr 2020 22:25:14 +0000 (15:25 -0700)
committerCarl Worth <cworth@cworth.org>
Sun, 26 Apr 2020 22:25:14 +0000 (15:25 -0700)
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

index 46eda0a12e7484a7dadaa48fbd8183e5f8b5509a..c62a9ea85d9bd8568e80e59f64b1be01eafabcfa 100644 (file)
--- 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 () {