feat: 환경 변수 및 Caddy 라우팅 설정 추가, 게임 API URL 템플릿 지원
This commit is contained in:
Vendored
+4
@@ -7,7 +7,11 @@ declare module '*.vue' {
|
||||
}
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_APP_BASE_PATH?: string;
|
||||
readonly VITE_GATEWAY_API_URL?: string;
|
||||
readonly VITE_GAME_API_URL_TEMPLATE?: string;
|
||||
readonly VITE_GAME_WEB_URL?: string;
|
||||
readonly VITE_GAME_WEB_URL_TEMPLATE?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
@@ -3,11 +3,18 @@ import type { appRouter } from '@sammo-ts/game-api';
|
||||
|
||||
export type GameRouter = typeof appRouter;
|
||||
|
||||
export const createGameTrpc = (port: number) => {
|
||||
const resolveProfileUrl = (template: string, profile: string): string =>
|
||||
template.replaceAll('{profile}', encodeURIComponent(profile));
|
||||
|
||||
export const createGameTrpc = (profile: string, port: number) => {
|
||||
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: `http://localhost:${port}/api/trpc`, // 실제 환경에서는 도메인/경로 조정 필요
|
||||
url,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ const getSessionToken = (): string | null => {
|
||||
export const trpc = createTRPCProxyClient<AppRouter>({
|
||||
links: [
|
||||
httpBatchLink({
|
||||
url: '/api/trpc', // 실제 환경에 맞게 조정 필요
|
||||
url: import.meta.env.VITE_GATEWAY_API_URL ?? '/api/trpc',
|
||||
headers() {
|
||||
const token = getSessionToken();
|
||||
return token ? { 'x-session-token': token } : {};
|
||||
|
||||
@@ -44,7 +44,7 @@ onMounted(async () => {
|
||||
if (profile.status !== 'RUNNING' && profile.status !== 'PREOPEN') {
|
||||
return;
|
||||
}
|
||||
const gameTrpc = createGameTrpc(profile.apiPort);
|
||||
const gameTrpc = createGameTrpc(profile.profile, profile.apiPort);
|
||||
const [infoResult, layoutResult, mapResult] = await Promise.allSettled([
|
||||
gameTrpc.lobby.info.query(),
|
||||
gameTrpc.public.getMapLayout.query(),
|
||||
@@ -78,7 +78,11 @@ const handleLogout = async () => {
|
||||
};
|
||||
|
||||
const resolveGameUrl = (path: string, profileName: string, gameToken: string): string | null => {
|
||||
const baseUrl = import.meta.env.VITE_GAME_WEB_URL ?? '';
|
||||
const profile = profileName.split(':', 1)[0] ?? profileName;
|
||||
const baseUrl =
|
||||
import.meta.env.VITE_GAME_WEB_URL ??
|
||||
import.meta.env.VITE_GAME_WEB_URL_TEMPLATE?.replaceAll('{profile}', encodeURIComponent(profile)) ??
|
||||
'';
|
||||
if (!baseUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user