Gateway 화면을 route 단위로 지연 로딩하고 common runtime import를 실제 소유 leaf export로 분리한다.\n\npackage boundary와 route loading 회귀 테스트로 root barrel 재유입을 차단한다.
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { trpcJsonBodyHttpClientOptions } from '@sammo-ts/common/http/trpcTransport';
|
|
import { createTRPCProxyClient, httpBatchLink, httpLink } from '@trpc/client';
|
|
import type { AppRouter } from '@sammo-ts/gateway-api';
|
|
|
|
const getSessionToken = (): string | null => {
|
|
if (typeof window === 'undefined') {
|
|
return null;
|
|
}
|
|
return window.localStorage.getItem('sammo-session-token');
|
|
};
|
|
|
|
export const trpc = createTRPCProxyClient<AppRouter>({
|
|
links: [
|
|
httpBatchLink({
|
|
url: import.meta.env.VITE_GATEWAY_API_URL ?? '/api/trpc',
|
|
...trpcJsonBodyHttpClientOptions,
|
|
headers() {
|
|
const token = getSessionToken();
|
|
return token ? { 'x-session-token': token } : {};
|
|
},
|
|
}),
|
|
],
|
|
});
|
|
|
|
export const directTrpc = createTRPCProxyClient<AppRouter>({
|
|
links: [
|
|
httpLink({
|
|
url: import.meta.env.VITE_GATEWAY_API_URL ?? '/api/trpc',
|
|
...trpcJsonBodyHttpClientOptions,
|
|
headers() {
|
|
const token = getSessionToken();
|
|
return token ? { 'x-session-token': token } : {};
|
|
},
|
|
}),
|
|
],
|
|
});
|