diff --git a/apps/client/src/network/SocketClient.ts b/apps/client/src/network/SocketClient.ts index e5dd3ae..f2b204d 100644 --- a/apps/client/src/network/SocketClient.ts +++ b/apps/client/src/network/SocketClient.ts @@ -1,5 +1,5 @@ import { io, Socket } from "socket.io-client"; -import { protocol } from "@repo/shared"; +import { protocol, config } from "@repo/shared"; import type { playerTypes, gridMapTypes, roomTypes } from "@repo/shared"; /** @@ -11,7 +11,9 @@ constructor() { // サーバー(バックエンド)のURLを直接指定する // 本番環境(Render)のURLを指定することで、プロキシなしで直接通信させます - const SERVER_URL = "localhost:3000"; // 開発環境用URL + const SERVER_URL = import.meta.env.PROD + ? config.NETWORK_CONFIG.PROD_SERVER_URL + : config.NETWORK_CONFIG.DEV_SERVER_URL; this.socket = io(SERVER_URL, { transports: ["websocket", "polling"], // 接続の安定性を高める diff --git a/apps/client/vite.config.ts b/apps/client/vite.config.ts index 977986a..1d5ea78 100644 --- a/apps/client/vite.config.ts +++ b/apps/client/vite.config.ts @@ -1,14 +1,21 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import { config } from '@repo/shared' -export default defineConfig({ - plugins: [react()], - server: { - proxy: { - '/socket.io': { - target: 'localhost:3000', - ws: true, - }, - }, - }, +export default defineConfig(({ mode }) => { + const isProd = mode === 'production' + + return { + plugins: [react()], + server: isProd + ? undefined + : { + proxy: { + '/socket.io': { + target: config.NETWORK_CONFIG.DEV_SERVER_URL, + ws: true, + }, + }, + }, + } }) \ No newline at end of file diff --git "a/docs/01_Env/ENV_01_\347\222\260\345\242\203\346\247\213\347\257\211\343\203\273\346\212\200\350\241\223\343\202\271\343\202\277\343\203\203\343\202\257.txt" "b/docs/01_Env/ENV_01_\347\222\260\345\242\203\346\247\213\347\257\211\343\203\273\346\212\200\350\241\223\343\202\271\343\202\277\343\203\203\343\202\257.txt" index f412115..af04675 100644 --- "a/docs/01_Env/ENV_01_\347\222\260\345\242\203\346\247\213\347\257\211\343\203\273\346\212\200\350\241\223\343\202\271\343\202\277\343\203\203\343\202\257.txt" +++ "b/docs/01_Env/ENV_01_\347\222\260\345\242\203\346\247\213\347\257\211\343\203\273\346\212\200\350\241\223\343\202\271\343\202\277\343\203\203\343\202\257.txt" @@ -114,6 +114,7 @@ │ │ ├── player/ │ │ │ └── player.type.ts # プレイヤー型 │ │ └── room/ + │ │ ├── room.const.ts # ルーム定数 │ │ └── room.type.ts # ルーム型 │ └── protocol/ │ └── events.ts # 通信イベント定義 diff --git a/packages/shared/src/config/gameConfig.ts b/packages/shared/src/config/gameConfig.ts index 7d0ef50..6a2c0ed 100644 --- a/packages/shared/src/config/gameConfig.ts +++ b/packages/shared/src/config/gameConfig.ts @@ -39,4 +39,9 @@ MAP_BG_COLOR: 0x111111, // 何も塗っていないマス(背景)の色 MAP_GRID_COLOR: 0x333333, // グリッド線の色 MAP_BORDER_COLOR: 0xff4444, // プレイ領域外枠の色 +} as const; + +export const NETWORK_CONFIG = { + DEV_SERVER_URL: "http://localhost:3000", + PROD_SERVER_URL: "https://skillsemiwebgame.onrender.com", } as const; \ No newline at end of file