import Koa from "koa"; import Router from "@koa/router"; import { Blackjack } from "./blackjack/Blackjack"; import { itemResponse, itemsResponse } from "./serverResponse"; const PORT = 3000; const app = new Koa(); const router = new Router(); const tables: Blackjack[] = []; router.get("/table", (ctx) => { ctx.status = 200; ctx.body = itemsResponse(tables); }); router.get("/table/:id", (ctx) => { const id = ctx.params["id"]; ctx.status = 200; ctx.body = itemResponse(tables[Number(id)]); }); router.post("/table", (ctx) => { const id = tables.length; tables.push(new Blackjack(id)); ctx.status = 201; ctx.body = { id }; }); app.use(router.routes()); app.listen(3000, () => console.log(`listening on port ${PORT}`));