add game id route
This commit is contained in:
parent
ceaf70ef05
commit
c4e399d3d4
@ -11,7 +11,7 @@ const gameStore = new GameStoreImpl();
|
|||||||
const matchMaker = new MatchMakerImpl({ rtmt });
|
const matchMaker = new MatchMakerImpl({ rtmt });
|
||||||
const gameManager = new GameManager({ rtmt, gameStore, matchMaker })
|
const gameManager = new GameManager({ rtmt, gameStore, matchMaker })
|
||||||
|
|
||||||
const expressApp = new ExpressApp();
|
const expressApp = new ExpressApp({ gameStore });
|
||||||
const server = new WebServer({ expressApp: expressApp.app });
|
const server = new WebServer({ expressApp: expressApp.app });
|
||||||
|
|
||||||
rtmt.initWebSocket(server.server, (userKey: string) => gameManager.fireOnPlayerConnected(userKey));
|
rtmt.initWebSocket(server.server, (userKey: string) => gameManager.fireOnPlayerConnected(userKey));
|
||||||
|
|||||||
@ -4,10 +4,13 @@ import { Request, Response } from "express";
|
|||||||
import morgan from "morgan";
|
import morgan from "morgan";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { generateKey } from "../util/key_factory";
|
import { generateKey } from "../util/key_factory";
|
||||||
|
import { GameStore } from "../game/gamestore/GameStore";
|
||||||
|
|
||||||
export class ExpressApp {
|
export class ExpressApp {
|
||||||
app: Express.Application;
|
app: Express.Application;
|
||||||
constructor() {
|
gameStore: GameStore;
|
||||||
|
constructor(params: { gameStore: GameStore }) {
|
||||||
|
this.gameStore = params.gameStore;
|
||||||
this.app = this.createExpressApp();
|
this.app = this.createExpressApp();
|
||||||
}
|
}
|
||||||
private createAccessLogMiddleware() {
|
private createAccessLogMiddleware() {
|
||||||
@ -26,6 +29,17 @@ export class ExpressApp {
|
|||||||
app.get("/register/", (req: Request, res: Response) => {
|
app.get("/register/", (req: Request, res: Response) => {
|
||||||
res.send(generateKey());
|
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;
|
return app;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user