diff --git a/configs/config.js b/configs/config.js new file mode 100644 index 0000000..baae7b8 --- /dev/null +++ b/configs/config.js @@ -0,0 +1,4 @@ +window.__APP_CONFIG__ = { + backendBaseUrl: "http://leda.kraysent.dev", + adminBaseUrl: "http://leda.kraysent.dev" +}; diff --git a/index.html b/index.html index 390b975..49db93f 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@ + HyperLEDA diff --git a/makefile b/makefile index 93a0fbf..fc6ecd7 100644 --- a/makefile +++ b/makefile @@ -15,8 +15,8 @@ fix: yarn eslint --fix src gen: - yarn run openapi-ts -i http://dm2.sao.ru:81/api/openapi.json -o ./src/clients/backend - yarn run openapi-ts -i http://dm2.sao.ru:81/admin/api/openapi.json -o ./src/clients/admin + yarn run openapi-ts -i http://leda.sao.ru/api/openapi.json -o ./src/clients/backend + yarn run openapi-ts -i http://leda.sao.ru/admin/api/openapi.json -o ./src/clients/admin image-build: docker build . -t ghcr.io/hyperleda/hyperleda-webapp:$(GIT_VERSION) diff --git a/src/clients/config.ts b/src/clients/config.ts new file mode 100644 index 0000000..63d0aee --- /dev/null +++ b/src/clients/config.ts @@ -0,0 +1,11 @@ +import { createClient as createBackendClient } from "./backend/client"; +import { createClient as createAdminClient } from "./admin/client"; +import { config } from "../config"; + +export const backendClient = createBackendClient({ + baseUrl: config.backendBaseUrl, +}); + +export const adminClient = createAdminClient({ + baseUrl: config.adminBaseUrl, +}); diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..786a18d --- /dev/null +++ b/src/config.ts @@ -0,0 +1,22 @@ +interface AppConfig { + backendBaseUrl: string; + adminBaseUrl: string; +} + +declare global { + interface Window { + __APP_CONFIG__?: AppConfig; + } +} + +function getConfig(): AppConfig { + if (typeof window === "undefined" || !window.__APP_CONFIG__) { + throw new Error( + "App configuration is required. Please set window.__APP_CONFIG__", + ); + } + + return window.__APP_CONFIG__; +} + +export const config = getConfig(); diff --git a/src/pages/CrossmatchResults.tsx b/src/pages/CrossmatchResults.tsx index 44f956e..ba9a6b7 100644 --- a/src/pages/CrossmatchResults.tsx +++ b/src/pages/CrossmatchResults.tsx @@ -22,6 +22,7 @@ import { ErrorPage } from "../components/ui/error-page"; import { Link } from "../components/ui/link"; import { useDataFetching } from "../hooks/useDataFetching"; import { Pagination } from "../components/ui/pagination"; +import { adminClient } from "../clients/config"; interface CrossmatchFiltersProps { tableName: string | null; @@ -171,6 +172,7 @@ async function fetcher( } const response = await getCrossmatchRecordsAdminApiV1RecordsCrossmatchGet({ + client: adminClient, query: { table_name: tableName, status: status, diff --git a/src/pages/ObjectDetails.tsx b/src/pages/ObjectDetails.tsx index 1975496..b6d16d4 100644 --- a/src/pages/ObjectDetails.tsx +++ b/src/pages/ObjectDetails.tsx @@ -8,6 +8,7 @@ import { Link } from "../components/ui/link"; import { querySimpleApiV1QuerySimpleGet } from "../clients/backend/sdk.gen"; import { PgcObject, Schema } from "../clients/backend/types.gen"; import { useDataFetching } from "../hooks/useDataFetching"; +import { backendClient } from "../clients/config"; interface ObjectDetailsProps { object: PgcObject; @@ -55,6 +56,7 @@ async function fetcher( } const response = await querySimpleApiV1QuerySimpleGet({ + client: backendClient, query: { pgcs: [Number(pgcId)], }, diff --git a/src/pages/RecordCrossmatchDetails.tsx b/src/pages/RecordCrossmatchDetails.tsx index cbcbcf5..3a430a8 100644 --- a/src/pages/RecordCrossmatchDetails.tsx +++ b/src/pages/RecordCrossmatchDetails.tsx @@ -15,6 +15,7 @@ import { Schema as BackendSchema } from "../clients/backend/types.gen"; import { getResource } from "../resources/resources"; import { Link } from "../components/ui/link"; import { useDataFetching } from "../hooks/useDataFetching"; +import { adminClient } from "../clients/config"; // TODO: remove when admin api uses the same structures as data api function convertAdminSchemaToBackendSchema( @@ -188,6 +189,7 @@ async function fetcher( } const response = await getRecordCrossmatchAdminApiV1RecordCrossmatchGet({ + client: adminClient, query: { record_id: recordId, }, diff --git a/src/pages/SearchResults.tsx b/src/pages/SearchResults.tsx index 936bb8b..e70e186 100644 --- a/src/pages/SearchResults.tsx +++ b/src/pages/SearchResults.tsx @@ -14,6 +14,7 @@ import { QuerySimpleResponse } from "../clients/backend/types.gen"; import { Link } from "../components/ui/link"; import { Declination, RightAscension } from "../components/ui/astronomy"; import { Pagination } from "../components/ui/pagination"; +import { backendClient } from "../clients/config"; function searchHandler(navigate: NavigateFunction) { return function f(query: string) { @@ -125,6 +126,7 @@ async function fetcher( } const response = await querySimpleApiV1QuerySimpleGet({ + client: backendClient, query: { name: query, page: page, diff --git a/src/pages/TableDetails.tsx b/src/pages/TableDetails.tsx index 4133fed..0c5c22e 100644 --- a/src/pages/TableDetails.tsx +++ b/src/pages/TableDetails.tsx @@ -19,6 +19,7 @@ import { Loading } from "../components/ui/loading"; import { ErrorPage } from "../components/ui/error-page"; import { getResource } from "../resources/resources"; import { useDataFetching } from "../hooks/useDataFetching"; +import { backendClient } from "../clients/config"; function renderBibliography(bib: Bibliography): ReactElement { let authors = ""; @@ -267,6 +268,7 @@ async function fetcher( } const response = await getTableAdminApiV1TableGet({ + client: backendClient, query: { table_name: tableName }, }); if (response.error) {