From 0265afad5b35e9ae6d9b3dcc5f6a9cea424a3b32 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 13 May 2026 13:07:40 +0200 Subject: [PATCH] chore: enhance Nginx configuration for direct access and update main entry point to dynamically resolve Router basename based on environment settings --- frontend/nginx.conf | 5 +++++ frontend/src/main.jsx | 45 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/frontend/nginx.conf b/frontend/nginx.conf index 6fa4421..b53a317 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -6,6 +6,11 @@ server { root /app/dist; index index.html; + # Acceso directo al puerto (sin Apache): misma app bajo el prefijo del build. + location = / { + return 301 /orcid2words/; + } + # Apache forwards the full path; strip /orcid2words/ before resolving files under dist/. location = /orcid2words { return 301 /orcid2words/; diff --git a/frontend/src/main.jsx b/frontend/src/main.jsx index be0f423..824e95e 100644 --- a/frontend/src/main.jsx +++ b/frontend/src/main.jsx @@ -1,13 +1,40 @@ -import { StrictMode } from 'react' -import { createRoot } from 'react-dom/client' -import { BrowserRouter } from 'react-router-dom' -import App from './App.jsx' -import './index.css' +import { StrictMode } from "react"; +import { createRoot } from "react-dom/client"; +import { BrowserRouter } from "react-router-dom"; +import App from "./App.jsx"; +import "./index.css"; -createRoot(document.getElementById('root')).render( +/** + * `import.meta.env.BASE_URL` es fijo en build (p. ej. `/orcid2words/` en prod). + * Los assets siguen bajo ese prefijo, pero la URL del documento puede ser `/` + * (acceso directo `http://host:8073/`). React Router exige que el pathname + * empiece por el basename; si no, no renderiza nada. + */ +function resolveRouterBasename() { + const configured = import.meta.env.BASE_URL ?? "/"; + const withSlash = configured.endsWith("/") ? configured : `${configured}/`; + + if (withSlash === "/") { + return "/"; + } + + const { pathname } = window.location; + if (pathname === "/" || pathname === "") { + return "/"; + } + + const prefix = withSlash.replace(/\/$/, ""); + if (pathname === prefix || pathname.startsWith(`${prefix}/`)) { + return withSlash; + } + + return "/"; +} + +createRoot(document.getElementById("root")).render( - + - -) \ No newline at end of file + , +);