Embezzle/index.js
2020-02-16 10:53:52 +02:00

81 lines
1.8 KiB
JavaScript

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)
res.send(JSON.stringify({gamesArr: r }))
})
})
//get game details
app.get('/lobby/details/:gameID', function (req, res) {
let obj=req.body
lobby.details(obj.gameID).then(r => {
res.send(JSON.stringify(r))
})
})
//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)