add game id route

This commit is contained in:
Halit Aksoy 2022-07-30 16:14:37 +03:00
parent ceaf70ef05
commit c4e399d3d4
2 changed files with 16 additions and 2 deletions

View File

@ -11,7 +11,7 @@ const gameStore = new GameStoreImpl();
const matchMaker = new MatchMakerImpl({ rtmt });
const gameManager = new GameManager({ rtmt, gameStore, matchMaker })
const expressApp = new ExpressApp();
const expressApp = new ExpressApp({ gameStore });
const server = new WebServer({ expressApp: expressApp.app });
rtmt.initWebSocket(server.server, (userKey: string) => gameManager.fireOnPlayerConnected(userKey));

View File

@ -4,10 +4,13 @@ import { Request, Response } from "express";
import morgan from "morgan";
import fs from "fs";
import { generateKey } from "../util/key_factory";
import { GameStore } from "../game/gamestore/GameStore";
export class ExpressApp {
app: Express.Application;
constructor() {
gameStore: GameStore;
constructor(params: { gameStore: GameStore }) {
this.gameStore = params.gameStore;
this.app = this.createExpressApp();
}
private createAccessLogMiddleware() {
@ -26,6 +29,17 @@ export class ExpressApp {
app.get("/register/", (req: Request, res: Response) => {
res.send(generateKey());
});
app.get("/game/:id", (req: Request, res: Response) => {
const gameId = req.params.id;
const game = this.gameStore.get(gameId);
if(game) {
res.send(game)
} else {
res.sendStatus(404)
}
});
return app;
}
}