브라우저의 Gateway·Game tRPC 클라이언트를 POST JSON 전송으로 통일하고 서버의 query method override를 허용한다. GET mutation 거부 계약과 production Chromium 요청 형태를 회귀 테스트로 고정한다.
25 lines
767 B
TypeScript
25 lines
767 B
TypeScript
import { trpcJsonBodyHttpClientOptions } from '@sammo-ts/common';
|
|
import { createTRPCProxyClient, httpBatchLink } 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 gatewayTrpc = 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 } : {};
|
|
},
|
|
}),
|
|
],
|
|
});
|