chore: enhance Nginx configuration for direct access and update main entry point to dynamically resolve Router basename based on environment settings
This commit is contained in:
@@ -6,6 +6,11 @@ server {
|
|||||||
root /app/dist;
|
root /app/dist;
|
||||||
index index.html;
|
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/.
|
# Apache forwards the full path; strip /orcid2words/ before resolving files under dist/.
|
||||||
location = /orcid2words {
|
location = /orcid2words {
|
||||||
return 301 /orcid2words/;
|
return 301 /orcid2words/;
|
||||||
|
|||||||
+36
-9
@@ -1,13 +1,40 @@
|
|||||||
import { StrictMode } from 'react'
|
import { StrictMode } from "react";
|
||||||
import { createRoot } from 'react-dom/client'
|
import { createRoot } from "react-dom/client";
|
||||||
import { BrowserRouter } from 'react-router-dom'
|
import { BrowserRouter } from "react-router-dom";
|
||||||
import App from './App.jsx'
|
import App from "./App.jsx";
|
||||||
import './index.css'
|
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(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<BrowserRouter basename={import.meta.env.BASE_URL}>
|
<BrowserRouter basename={resolveRouterBasename()}>
|
||||||
<App />
|
<App />
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</StrictMode>
|
</StrictMode>,
|
||||||
)
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user