diff --git a/.env.example b/.env.example index 880bfae..9e187ca 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ BASE_URL=http://localhost:3000 +NEXT_PUBLIC_BASE_URL=http://localhost:3100 API_URL=http://localhost:7999 # Enable or disable authentication if disabled it will mock the user and session diff --git a/src/components/search-provider.tsx b/src/components/search-provider.tsx index ad70b5b..c5bce17 100644 --- a/src/components/search-provider.tsx +++ b/src/components/search-provider.tsx @@ -2,12 +2,13 @@ import { SearchRequest, SearchResponse } from '@/lib/client'; import { PropsWithChildren, use, useCallback, useEffect, useMemo } from 'react'; +import { Host } from '@clinia/client-common'; import client from '@clinia/client-datapartition'; import { SearchParameters, type SearchSDKOptions, } from '@clinia/search-sdk-core'; -import { SearchSDKProvider, useCollection } from '@clinia/search-sdk-react'; +import { SearchSDKProvider } from '@clinia/search-sdk-react'; import { Collection } from '@clinia/search-sdk-react'; type SearchProviderProps = PropsWithChildren<{ @@ -17,6 +18,19 @@ type SearchProviderProps = PropsWithChildren<{ }; }>; +const getHost = (): Host => { + const url = new URL(`${process.env.NEXT_PUBLIC_BASE_URL}`); + if (url.host.endsWith('/')) { + url.host = url.host.slice(0, -1); + } + + return { + protocol: url.protocol.replace(':', '') as 'http' | 'https', + url: `${url.host}/api`, + accept: 'readWrite', + }; +}; + const datapartitionClient = client( 'clinia', { @@ -24,13 +38,7 @@ const datapartitionClient = client( bearerToken: '', }, { - hosts: [ - { - url: 'localhost:3100/api', - protocol: 'http', - accept: 'readWrite', - }, - ], + hosts: [getHost()], } );