const lobby = require("./lobby.js") const express = require('express') const bodyParser = require('body-parser'); const app = express() app.use(bodyParser.json(),function (req, res, next) { res.setHeader('Access-Control-Allow-Origin', '*') res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE') res.setHeader('Access-Control-Allow-Headers', 'Content-Type') res.setHeader('Access-Control-Allow-Credentials', true) next() }) //top level //get game list app.get('/lobby/list' , async function (req, res) { lobby.list().then(r => { console.log(r) }) console.log() result="" res.send(JSON.stringify({gamesArr: result })) }) //get game details app.get('/lobby/details', function (req, res) { let obj=req.body res.send(lobby.details(obj.gameID)) }) //post register player app.post('/lobby/register', function (req, res) { let obj=req.body console.log(req.body) response=JSON.stringify(lobby.register(obj.name)) res.send(response) }) //post join an existing game app.post('/lobby/join', function (req, res) { let obj=req.body response=JSON.stringify(lobby.join(obj.ownerID,obj.gameID)) res.send(response) }) //get an empty game made app.post('/lobby/make', function (req, res) { let obj=req.body response=JSON.stringify(lobby.make(obj.ownerID,obj.seats)) res.send(response) }) //start a game app.post('/lobby/start', function (req, res) { let obj=req.body response=JSON.stringify(lobby.start(obj.ownerID, obj.gameID)) res.send(response) }) //gamelevel (??) // get this game players // get charity details // get board funding details (how much money team has to work with) // post distribution // post accusation // get winner // get round status console.log("Up") app.listen(3000)