wip version of the api

This commit is contained in:
lila 2026-04-05 00:33:34 +02:00
parent c24967dc74
commit 7d80b20390
8 changed files with 61 additions and 3 deletions

View file

@ -1,12 +1,11 @@
import express from "express";
import type { Express } from "express";
import { apiRouter } from "./routes/apiRouter.js";
export function createApp() {
const app: Express = express();
app.get("/api/health", (_req, res) => {
res.json({ status: "ok" });
});
app.use("/api/v1", apiRouter);
return app;
}

View file

@ -0,0 +1,8 @@
import type { Request, Response } from "express";
import { prepareQuestions } from "../services/gameService.js";
export const getGame = async (req: Request, res: Response) => {
const query = gameRequestSchema.parse(req.query);
const questions = await prepareQuestions(query);
res.json({ success: true, data: questions });
};

View file

@ -0,0 +1,9 @@
import express from "express";
import { Router } from "express";
import { healthRouter } from "./healthRouter.js";
import { gameRouter } from "./gameRouter.js";
export const apiRouter: Router = express.Router();
apiRouter.use("/health", healthRouter);
apiRouter.use("/game", gameRouter);

View file

@ -0,0 +1,7 @@
import express from "express";
import type { Router } from "express";
import { createGame } from "../controllers/gameController.js";
export const gameRouter: Router = express.Router();
gameRouter.get("/", createGame);

View file

@ -0,0 +1,11 @@
import type { Request, Response } from "express";
export const healthRouter = (_req: Request, res: Response) => {
res
.status(200)
.json({
status: "ok",
uptime: process.uptime(),
timestamp: new Date().toISOString(),
});
};

View file

@ -0,0 +1,3 @@
export const prepareQuestions = async (params: object) => {
console.log(params);
};