Configurar URLs para usar rutas de nginx sin puertos
All checks were successful
build-and-deploy / build (push) Successful in 19s
build-and-deploy / deploy (push) Successful in 10s

This commit is contained in:
2025-08-15 13:41:12 -06:00
parent 48f560d4e1
commit 59f60328e2
2 changed files with 8 additions and 5 deletions

2
client/.env.production Normal file
View File

@@ -0,0 +1,2 @@
VITE_WS_URL=wss://snatchgame.nucleoriofrio.com/ws
VITE_API_URL=https://snatchgame.nucleoriofrio.com/api

View File

@@ -37,13 +37,14 @@ class ColyseusService {
constructor() { constructor() {
const defaultHost = typeof window !== "undefined" ? window.location.hostname : "localhost"; const defaultHost = typeof window !== "undefined" ? window.location.hostname : "localhost";
const defaultProtocol = typeof window !== "undefined" && window.location.protocol === "https:" ? "wss" : "ws"; const defaultProtocol = typeof window !== "undefined" && window.location.protocol === "https:" ? "wss" : "ws";
const defaultPort = 3000; const httpProtocol = typeof window !== "undefined" && window.location.protocol === "https:" ? "https" : "http";
const fallbackUrl = `${defaultProtocol}://${defaultHost}:${defaultPort}`;
// Para producción, usar las rutas de nginx sin puerto
const fallbackUrl = `${defaultProtocol}://${defaultHost}/ws`;
const apiFallback = `${httpProtocol}://${defaultHost}/api`;
const url = import.meta.env.VITE_WS_URL || fallbackUrl; const url = import.meta.env.VITE_WS_URL || fallbackUrl;
this.client = new Client(url); this.client = new Client(url);
const httpProtocol = typeof window !== "undefined" && window.location.protocol === "https:" ? "https" : "http";
const apiFallback = `${httpProtocol}://${defaultHost}:${defaultPort}/api`;
this.apiBase = (import.meta.env as any).VITE_API_URL || apiFallback; this.apiBase = (import.meta.env as any).VITE_API_URL || apiFallback;
} }