diff --git a/deploy/vps-gateway/nginx/prediqo.conf.template b/deploy/vps-gateway/nginx/prediqo.conf.template index 54115153..82542602 100644 --- a/deploy/vps-gateway/nginx/prediqo.conf.template +++ b/deploy/vps-gateway/nginx/prediqo.conf.template @@ -1,8 +1,21 @@ +# www → apex (évite double origine / cookies) +server { + listen 443 ssl; + http2 on; + server_name ${PREDIQO_DOMAIN_WWW}; + + ssl_certificate /etc/letsencrypt-prediqo/live/${PREDIQO_CERT_NAME}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt-prediqo/live/${PREDIQO_CERT_NAME}/privkey.pem; + ssl_protocols TLSv1.2 TLSv1.3; + + return 301 https://${PREDIQO_DOMAIN}$request_uri; +} + # Tloto / Prediqo — HTTPS sur 443 (URL publique sans port : https://${PREDIQO_DOMAIN}) server { listen 443 ssl; http2 on; - server_name ${PREDIQO_DOMAIN} ${PREDIQO_DOMAIN_WWW}; + server_name ${PREDIQO_DOMAIN}; ssl_certificate /etc/letsencrypt-prediqo/live/${PREDIQO_CERT_NAME}/fullchain.pem; ssl_certificate_key /etc/letsencrypt-prediqo/live/${PREDIQO_CERT_NAME}/privkey.pem; diff --git a/prediqo_web/src/shared/services/api.ts b/prediqo_web/src/shared/services/api.ts index 14210940..769951b2 100644 --- a/prediqo_web/src/shared/services/api.ts +++ b/prediqo_web/src/shared/services/api.ts @@ -6,7 +6,32 @@ import axios, { AxiosError } from 'axios'; import { readAuth, writeAuth, clearAuth } from '../auth/tokenStorage'; import { getOrCreateVisitorToken } from '../../features/support/utils/visitorToken'; -const baseURL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:4000'; +/** + * In production behind the VPS gateway, prefer same-origin (`''`) so + * https://tloto.net and https://www.tloto.net both call `/api/...` on the + * current host (avoids stale :9443 builds and www↔apex CORS failures). + */ +function resolveApiBaseUrl(): string { + const configured = String(import.meta.env.VITE_API_BASE_URL ?? '').trim(); + if (import.meta.env.DEV) { + return configured || 'http://localhost:4000'; + } + if (!configured || configured === 'same-origin') { + return ''; + } + if (typeof window !== 'undefined') { + try { + if (new URL(configured).host !== window.location.host) { + return ''; + } + } catch { + return ''; + } + } + return configured.replace(/\/$/, ''); +} + +const baseURL = resolveApiBaseUrl(); /** Preconfigured Axios instance targeting the backend API with JSON headers. */ export const api = axios.create({