Configure dev proxy to flights.test.aeroflot.ru and fix API endpoint paths
API functions now build the full localized path matching the Angular
EndpointService pattern (/api/flights/{version}/{locale}/{endpoint}).
The dev proxy forwards /api and /flights to the test backend.
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -38,7 +38,7 @@ export async function searchDestinations(
|
||||
query["arrival"] = params.arrival;
|
||||
}
|
||||
|
||||
return client.get<IDestinationsResponse>("destinations/1", query);
|
||||
return client.get<IDestinationsResponse>(`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<IFlightsMapDaysResponse>(path);
|
||||
return parseBinaryDays(response.days, params.date);
|
||||
}
|
||||
|
||||
@@ -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/",
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -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<IBoardResponse>("board", query);
|
||||
return client.get<IBoardResponse>(`flights/v1.1/${client.locale}/board`, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ export async function getFlightDetails(
|
||||
client: ApiClient,
|
||||
params: FlightDetailsParams,
|
||||
): Promise<IBoardResponse> {
|
||||
return client.get<IBoardResponse>("onlineboard/details", {
|
||||
return client.get<IBoardResponse>(`flights/v1.1/${client.locale}/onlineboard/details`, {
|
||||
flights: params.flights,
|
||||
dates: params.dates,
|
||||
});
|
||||
@@ -107,7 +107,7 @@ export async function getCalendarDays(
|
||||
params: CalendarParams,
|
||||
): Promise<string[]> {
|
||||
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<IDaysResponse>(path);
|
||||
return parseCalendarDays(response.days);
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -30,7 +30,7 @@ export async function searchSchedule(
|
||||
client: ApiClient,
|
||||
params: IScheduleSearchRequest,
|
||||
): Promise<IScheduleResponse> {
|
||||
return client.post<IScheduleResponse>("schedule/1", params);
|
||||
return client.post<IScheduleResponse>(`flights/1/${client.locale}/schedule`, params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +64,7 @@ export async function getScheduleDetails(
|
||||
if (date !== undefined) query[`dates[${i}]`] = date;
|
||||
}
|
||||
|
||||
return client.get<IScheduleDetailsResponse>("schedule/details", query);
|
||||
return client.get<IScheduleDetailsResponse>(`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<IScheduleDaysResponse>(path);
|
||||
return parseCalendarDays(response.days);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user