const http = require('http');
const { startGameServer } = require('./gameServer');
const games = require('../games.json');
const game = games.find((g) => g.id === 'stack');
const { broadcast } = startGameServer({ game, tiktokUsername: '', port: 3971, simulateWhenOffline: false });

http.createServer((req, res) => {
  if (req.method === 'POST' && req.url === '/simulate') {
    let body = '';
    req.on('data', c => body += c);
    req.on('end', () => { broadcast(JSON.parse(body)); res.end('ok'); });
  } else res.end('n/a');
}).listen(4971);
