Gateway 화면을 route 단위로 지연 로딩하고 common runtime import를 실제 소유 leaf export로 분리한다.\n\npackage boundary와 route loading 회귀 테스트로 root barrel 재유입을 차단한다.
23 lines
949 B
TypeScript
23 lines
949 B
TypeScript
import { trpcJsonBodyHttpClientOptions } from '@sammo-ts/common/http/trpcTransport';
|
|
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
|
|
import type { appRouter } from '@sammo-ts/game-api';
|
|
|
|
export type GameRouter = typeof appRouter;
|
|
|
|
const resolveProfileUrl = (template: string, profile: string): string =>
|
|
template.replaceAll('{profile}', encodeURIComponent(profile));
|
|
|
|
export const createGameTrpc = (profile: string, port: number, gameToken?: string) => {
|
|
const urlTemplate = import.meta.env.VITE_GAME_API_URL_TEMPLATE;
|
|
const url = urlTemplate ? resolveProfileUrl(urlTemplate, profile) : `http://localhost:${port}/api/trpc`;
|
|
return createTRPCProxyClient<GameRouter>({
|
|
links: [
|
|
httpBatchLink({
|
|
url,
|
|
...trpcJsonBodyHttpClientOptions,
|
|
headers: gameToken ? { authorization: `Bearer ${gameToken}` } : undefined,
|
|
}),
|
|
],
|
|
});
|
|
};
|