feat: /meta для версии в футере и устойчивый разбор JSON
Some checks failed
CI / build-and-test (pull_request) Has been cancelled

This commit is contained in:
Anton
2026-04-08 10:32:52 +03:00
parent f8b4ce7111
commit 83bc603b95
9 changed files with 66 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "calendar-run-backend",
"version": "1.0.1",
"version": "1.1.0",
"private": true,
"scripts": {
"build": "tsc",

View File

@@ -7,7 +7,9 @@ import racesRouter from "./routes/races";
export function createApp(): express.Express {
const app = express();
app.use(cors({ origin: config.corsOrigin, methods: ["GET", "POST", "PATCH", "DELETE"] }));
app.use(
cors({ origin: config.corsOrigin, methods: ["GET", "POST", "PATCH", "DELETE", "OPTIONS"] }),
);
app.use(express.json());
app.use(healthRouter);

View File

@@ -8,6 +8,11 @@ router.get("/health", (_req: Request, res: Response) => {
res.json({ status: "ok", version: getBackendVersion() });
});
/** Версия для UI; путь без «health», чтобы реже резался фильтрами/прокси. */
router.get("/meta", (_req: Request, res: Response) => {
res.json({ version: getBackendVersion() });
});
router.get("/ready", async (_req: Request, res: Response) => {
const dbOk = await checkDbConnection();
if (dbOk) {

View File

@@ -17,6 +17,18 @@ test("GET /api/health returns ok (prefix without proxy strip)", async () => {
assert.equal(res.body.status, "ok");
});
test("GET /meta returns version for UI footer", async () => {
const res = await request(app).get("/meta").expect(200);
assert.equal(typeof res.body.version, "string");
assert.ok(res.body.version.length > 0);
});
test("GET /api/meta mirrors GET /meta", async () => {
const res = await request(app).get("/api/meta").expect(200);
assert.equal(typeof res.body.version, "string");
assert.ok(res.body.version.length > 0);
});
test("GET /ready succeeds with mock database", async () => {
const res = await request(app).get("/ready").expect(200);
assert.equal(res.body.status, "ready");