diff --git a/index.js b/index.js index 658c85b..b9ff22f 100644 --- a/index.js +++ b/index.js @@ -20,16 +20,17 @@ app.use(bodyParser.json(),function (req, res, next) { app.get('/lobby/list' , async function (req, res) { lobby.list().then(r => { console.log(r) + res.send(JSON.stringify({gamesArr: r })) }) - console.log() - result="" - res.send(JSON.stringify({gamesArr: result })) }) //get game details -app.get('/lobby/details', function (req, res) { +app.get('/lobby/details/:gameID', function (req, res) { let obj=req.body - res.send(lobby.details(obj.gameID)) + lobby.details(obj.gameID).then(r => { + res.send(JSON.stringify(r)) + }) + }) //post register player diff --git a/lobby.js b/lobby.js index 073b63f..4a150d5 100644 --- a/lobby.js +++ b/lobby.js @@ -3,14 +3,12 @@ const uuidv4 = require('uuid/v4'); var lobby={ list: async () => { - mongo.get("embezzle","gamelist",{}).then(result => { - return(result) - }) + result = await mongo.get("embezzle","gamelist",{}) + return(result) }, - details: (gameID) => { - mongo.get("embezzle","gamelist",{"gameID":gameID}).then(result => { - return (result) - }) + details: async (gameID) => { + result = await mongo.get("embezzle","gamelist",{"gameID":gameID}) + return (result) }, register: (name) => { id=uuidv4()