Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Host for client #4

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 16 additions & 8 deletions src/components/search-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand All @@ -17,20 +18,27 @@ 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',
{
mode: 'BearerToken',
bearerToken: '',
},
{
hosts: [
{
url: 'localhost:3100/api',
protocol: 'http',
accept: 'readWrite',
},
],
hosts: [getHost()],
}
);

Expand Down
Loading