diff --git a/backend/package.json b/backend/package.json index 39246cb..3ea74e5 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "calendar-run-backend", - "version": "1.0.0", + "version": "1.0.1", "private": true, "scripts": { "build": "tsc", diff --git a/backend/src/app.ts b/backend/src/app.ts index 76ae6c0..fa620b8 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -12,6 +12,9 @@ export function createApp(): express.Express { app.use(healthRouter); app.use(racesRouter); + // Тот же API под /api/* — если прокси не снимает префикс или запрос идёт напрямую на порт бэкенда с /api. + app.use("/api", healthRouter); + app.use("/api", racesRouter); app.use((err: unknown, _req: Request, res: Response, _next: NextFunction) => { if (err instanceof SyntaxError && "body" in err) { diff --git a/backend/test/app.test.ts b/backend/test/app.test.ts index ff852e4..3fdedeb 100644 --- a/backend/test/app.test.ts +++ b/backend/test/app.test.ts @@ -12,6 +12,11 @@ test("GET /health returns ok", async () => { assert.ok(res.body.version.length > 0); }); +test("GET /api/health returns ok (prefix without proxy strip)", async () => { + const res = await request(app).get("/api/health").expect(200); + assert.equal(res.body.status, "ok"); +}); + test("GET /ready succeeds with mock database", async () => { const res = await request(app).get("/ready").expect(200); assert.equal(res.body.status, "ready"); @@ -34,6 +39,11 @@ test("GET /races accepts year and month", async () => { assert.ok(Array.isArray(res.body)); }); +test("GET /api/races mirrors GET /races", async () => { + const res = await request(app).get("/api/races?year=2026&month=5").expect(200); + assert.ok(Array.isArray(res.body)); +}); + test("GET /races/:id returns not_found", async () => { const res = await request(app).get("/races/does-not-exist").expect(404); assert.equal(res.body.error, "not_found"); diff --git a/frontend/package.json b/frontend/package.json index 38f6bd0..e52b06d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "calendar-run-frontend", "private": true, - "version": "0.1.0", + "version": "0.1.1", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/src/api/http.ts b/frontend/src/api/http.ts index 9aaac54..bbc99d4 100644 --- a/frontend/src/api/http.ts +++ b/frontend/src/api/http.ts @@ -35,10 +35,15 @@ export async function requestJson(path: string, init?: RequestInit): Promise< for (let attempt = 1; attempt <= maxAttempts; attempt += 1) { try { + const defaultHeaders: Record = {}; + if (method !== "GET" && method !== "HEAD") { + defaultHeaders["Content-Type"] = "application/json"; + } + const response = await fetch(buildUrl(path), { ...init, headers: { - "Content-Type": "application/json", + ...defaultHeaders, ...(init?.headers ?? {}), }, }); @@ -55,25 +60,6 @@ export async function requestJson(path: string, init?: RequestInit): Promise< await delay(80 * attempt); continue; } - // #region agent log - fetch("http://127.0.0.1:7488/ingest/a18f912f-72c6-4a58-866b-17810a6b89d2", { - method: "POST", - headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "587ee5" }, - body: JSON.stringify({ - sessionId: "587ee5", - hypothesisId: "H-http-not-ok", - location: "http.ts:requestJson", - message: "HTTP error response", - data: { - path, - status: response.status, - contentType: response.headers.get("content-type"), - payloadIsObject: payload !== null && typeof payload === "object", - }, - timestamp: Date.now(), - }), - }).catch(() => {}); - // #endregion throw toApiError(response.status, payload); }