better base_path support.

This commit is contained in:
arabcoders 2025-09-05 12:54:41 +03:00
parent b01c0049ae
commit adb72f4584
3 changed files with 7 additions and 4 deletions

View file

@ -263,14 +263,14 @@ class HttpAPI:
response: Response = await handler(request)
contentType: str | None = response.headers.get("content-type", None)
if contentType and "/" != base_path and contentType.startswith("text/html"):
if contentType and contentType.startswith("text/html"):
rewrite_path: str = base_path.rstrip("/")
async with await anyio.open_file(response._path, "rb") as f:
content = await f.read()
content: str = (
content.decode("utf-8")
.replace('<base href="/">', f'<base href="{rewrite_path}/">')
.replace('baseURL:""', f'baseURL:"{rewrite_path}/"')
.replace("/_base_path/", f"{rewrite_path}/")
)
new_response = web.Response(text=content, content_type="text/html")

View file

@ -359,6 +359,9 @@ class Config:
if isinstance(self.pictures_backends, str) and self.pictures_backends:
self.pictures_backends = self.pictures_backends.split(",")
if not self.base_path.endswith("/"):
self.base_path += "/"
numeric_level = getattr(logging, self.log_level.upper(), None)
if not isinstance(numeric_level, int):
msg = f"Invalid log level '{self.log_level}' specified."
@ -371,7 +374,7 @@ class Config:
encoding="utf-8",
)
LOG = logging.getLogger("config")
LOG: logging.Logger = logging.getLogger("config")
if self.debug:
try:

View file

@ -37,7 +37,7 @@ export default defineNuxtConfig({
transpile: ['vue-toastification'],
},
app: {
baseURL: 'production' == process.env.NODE_ENV ? '' : '/',
baseURL: 'production' == process.env.NODE_ENV ? '/_base_path/' : '/',
buildAssetsDir: "assets",
head: {
"meta": [