forked from Chainlit/chainlit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
30 lines (24 loc) · 783 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import getRouterBasename from '@/lib/router';
import { toast } from 'sonner';
import { ChainlitAPI, ClientError } from '@chainlit/react-client';
const devServer = 'http://localhost:8000' + getRouterBasename();
const url = import.meta.env.DEV
? devServer
: window.origin + getRouterBasename();
const serverUrl = new URL(url);
const httpEndpoint = serverUrl.toString();
const on401 = () => {
if (window.location.pathname !== getRouterBasename() + '/login') {
// The credentials aren't correct, remove the token and redirect to login
window.location.href = getRouterBasename() + '/login';
}
};
const onError = (error: ClientError) => {
toast.error(error.toString());
};
export const apiClient = new ChainlitAPI(
httpEndpoint,
'webapp',
on401,
onError
);