diff --git a/modern.config.ts b/modern.config.ts index 769fffa7..3ffc29d6 100644 --- a/modern.config.ts +++ b/modern.config.ts @@ -12,6 +12,12 @@ export default defineConfig({ runtime: { router: true, }, + dev: { + proxy: { + "/api": "https://flights.test.aeroflot.ru/api", + "/flights": "https://flights.test.aeroflot.ru/flights", + }, + }, server: { ssr: { mode: "stream", diff --git a/src/features/flights-map/api.test.ts b/src/features/flights-map/api.test.ts index 07f44592..93338e01 100644 --- a/src/features/flights-map/api.test.ts +++ b/src/features/flights-map/api.test.ts @@ -65,7 +65,7 @@ describe("searchDestinations", () => { await searchDestinations(client, params); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/destinations/1"); + expect(url.pathname).toBe("/flights/1/ru/destinations"); expect(url.searchParams.get("departure")).toBe("SVO"); expect(url.searchParams.get("arrival")).toBe("LED"); expect(url.searchParams.get("dateFrom")).toBe("20250601"); @@ -143,7 +143,7 @@ describe("getFlightsMapCalendar", () => { }); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/days/20250601/200/route/SVO-LED/flights-map/v1"); + expect(url.pathname).toBe("/flights/v1/ru/days/20250601/200/route/SVO-LED/flights-map/"); }); it("builds correct path for connecting route", async () => { @@ -158,7 +158,7 @@ describe("getFlightsMapCalendar", () => { const url = extractUrl(mockFetch); expect(url.pathname).toBe( - "/days/20250601/200/connections/SVO-LED-1/flights-map/v1", + "/flights/v1/ru/days/20250601/200/connections/SVO-LED-1/flights-map/", ); }); @@ -172,7 +172,7 @@ describe("getFlightsMapCalendar", () => { }); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/days/20250601/200/departure/SVO/flights-map/v1"); + expect(url.pathname).toBe("/flights/v1/ru/days/20250601/200/departure/SVO/flights-map/"); }); it("parses binary days string into available date strings", async () => { diff --git a/src/features/flights-map/api.ts b/src/features/flights-map/api.ts index 222f0be8..f32b747f 100644 --- a/src/features/flights-map/api.ts +++ b/src/features/flights-map/api.ts @@ -38,7 +38,7 @@ export async function searchDestinations( query["arrival"] = params.arrival; } - return client.get("destinations/1", query); + return client.get(`flights/1/${client.locale}/destinations`, query); } /** @@ -56,7 +56,7 @@ export async function getFlightsMapCalendar( const routeSegment = buildRouteSegment(params); if (!routeSegment) return []; - const path = `days/${params.date}/200/${routeSegment}/flights-map/v1`; + const path = `flights/v1/${client.locale}/days/${params.date}/200/${routeSegment}/flights-map/`; const response = await client.get(path); return parseBinaryDays(response.days, params.date); } diff --git a/src/features/online-board/api.test.ts b/src/features/online-board/api.test.ts index 29dbd9dd..48396cc5 100644 --- a/src/features/online-board/api.test.ts +++ b/src/features/online-board/api.test.ts @@ -72,7 +72,7 @@ describe("searchFlights", () => { await searchFlights(client, params); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/board"); + expect(url.pathname).toBe("/flights/v1.1/ru/board"); expect(url.searchParams.get("dateFrom")).toBe("20250115"); expect(url.searchParams.get("dateTo")).toBe("20250116"); }); @@ -172,7 +172,7 @@ describe("getFlightDetails", () => { await getFlightDetails(client, params); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/onlineboard/details"); + expect(url.pathname).toBe("/flights/v1.1/ru/onlineboard/details"); expect(url.searchParams.get("flights")).toBe("SU100"); expect(url.searchParams.get("dates")).toBe("2025-01-15"); }); @@ -214,7 +214,7 @@ describe("getCalendarDays", () => { await getCalendarDays(client, params); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/v1/days/2025-01-15/31/flight/SU100/board/"); + expect(url.pathname).toBe("/flights/v1/ru/days/2025-01-15/31/flight/SU100/board/"); }); it("builds correct path for departure type", async () => { @@ -227,7 +227,7 @@ describe("getCalendarDays", () => { }); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/v1/days/2025-01-15/31/departure/SVO/board/"); + expect(url.pathname).toBe("/flights/v1/ru/days/2025-01-15/31/departure/SVO/board/"); }); it("builds correct path for arrival type", async () => { @@ -240,7 +240,7 @@ describe("getCalendarDays", () => { }); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/v1/days/2025-01-15/31/arrival/JFK/board/"); + expect(url.pathname).toBe("/flights/v1/ru/days/2025-01-15/31/arrival/JFK/board/"); }); it("builds correct path for route type", async () => { @@ -255,7 +255,7 @@ describe("getCalendarDays", () => { const url = extractUrl(mockFetch); expect(url.pathname).toBe( - "/v1/days/2025-01-15/31/route/SVO-JFK/board/", + "/flights/v1/ru/days/2025-01-15/31/route/SVO-JFK/board/", ); }); diff --git a/src/features/online-board/api.ts b/src/features/online-board/api.ts index 9abc5899..4a1f7910 100644 --- a/src/features/online-board/api.ts +++ b/src/features/online-board/api.ts @@ -78,7 +78,7 @@ export async function searchFlights( if (params.timeFrom) query["timeFrom"] = params.timeFrom; if (params.timeTo) query["timeTo"] = params.timeTo; - return client.get("board", query); + return client.get(`flights/v1.1/${client.locale}/board`, query); } /** @@ -89,7 +89,7 @@ export async function getFlightDetails( client: ApiClient, params: FlightDetailsParams, ): Promise { - return client.get("onlineboard/details", { + return client.get(`flights/v1.1/${client.locale}/onlineboard/details`, { flights: params.flights, dates: params.dates, }); @@ -107,7 +107,7 @@ export async function getCalendarDays( params: CalendarParams, ): Promise { const searchSegment = buildCalendarSearchSegment(params); - const path = `v1/days/${params.date}/31/${searchSegment}/board/`; + const path = `flights/v1/${client.locale}/days/${params.date}/31/${searchSegment}/board/`; const response = await client.get(path); return parseCalendarDays(response.days); diff --git a/src/features/schedule/api.test.ts b/src/features/schedule/api.test.ts index 625a9c8d..c6344eed 100644 --- a/src/features/schedule/api.test.ts +++ b/src/features/schedule/api.test.ts @@ -82,7 +82,7 @@ describe("searchSchedule", () => { await searchSchedule(client, params); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/schedule/1"); + expect(url.pathname).toBe("/flights/1/ru/schedule"); expect(extractMethod(mockFetch)).toBe("POST"); }); @@ -146,7 +146,7 @@ describe("getScheduleDetails", () => { }); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/schedule/details"); + expect(url.pathname).toBe("/flights/v1.1/ru/schedule/details"); expect(url.searchParams.get("flights[0]")).toBe("SU0012"); expect(url.searchParams.get("flights[1]")).toBe("SU0013"); expect(url.searchParams.get("dates[0]")).toBe("2025-01-15"); @@ -198,7 +198,7 @@ describe("getScheduleCalendarDays", () => { }); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/v1/days/2025-01-15/382/route/SVO-LED/schedule/"); + expect(url.pathname).toBe("/flights/v1/ru/days/2025-01-15/382/route/SVO-LED/schedule/"); }); it("builds correct path for route with connections", async () => { @@ -212,7 +212,7 @@ describe("getScheduleCalendarDays", () => { }); const url = extractUrl(mockFetch); - expect(url.pathname).toBe("/v1/days/2025-01-15/382/connections/SVO-LED-1/schedule/"); + expect(url.pathname).toBe("/flights/v1/ru/days/2025-01-15/382/connections/SVO-LED-1/schedule/"); }); it("parses comma-separated days string into array", async () => { diff --git a/src/features/schedule/api.ts b/src/features/schedule/api.ts index 58307c84..2ba4ac49 100644 --- a/src/features/schedule/api.ts +++ b/src/features/schedule/api.ts @@ -30,7 +30,7 @@ export async function searchSchedule( client: ApiClient, params: IScheduleSearchRequest, ): Promise { - return client.post("schedule/1", params); + return client.post(`flights/1/${client.locale}/schedule`, params); } /** @@ -64,7 +64,7 @@ export async function getScheduleDetails( if (date !== undefined) query[`dates[${i}]`] = date; } - return client.get("schedule/details", query); + return client.get(`flights/v1.1/${client.locale}/schedule/details`, query); } /** @@ -82,7 +82,7 @@ export async function getScheduleCalendarDays( ? `connections/${params.departure}-${params.arrival}-1` : `route/${params.departure}-${params.arrival}`; - const path = `v1/days/${params.date}/382/${routeSegment}/schedule/`; + const path = `flights/v1/${client.locale}/days/${params.date}/382/${routeSegment}/schedule/`; const response = await client.get(path); return parseCalendarDays(response.days); diff --git a/src/shared/api/client.ts b/src/shared/api/client.ts index 3d9aacc3..68e22a3d 100644 --- a/src/shared/api/client.ts +++ b/src/shared/api/client.ts @@ -22,7 +22,7 @@ const DEFAULT_RETRY_STATUS_CODES = [408, 429, 500, 502, 503, 504]; export class ApiClient { private readonly baseUrl: string; - private readonly locale: Language; + readonly locale: Language; private readonly traceId: string | undefined; private readonly fetchFn: typeof fetch; private readonly timeoutMs: number;