Files
OmniRoute/scripts/build/normalizeBasePath.mjs
AmirHossein Rezaei bb5cb51f3e fix(docker): honor OMNIROUTE_BASE_PATH behind reverse-proxy subpaths (#8615)
* fix(docker): honor OMNIROUTE_BASE_PATH behind reverse-proxy subpaths

Next.js basePath is compile-time state; Docker now records the baked value,
forwards the env var as a build-arg, patches root-path images at container
start when needed, and probes health under the active subpath.

Hard Rule #13: scripts/docker/patch-basepath.sh and the entrypoint invoke Node
with a fixed argv; OMNIROUTE_BASE_PATH is read from process.env only — never
interpolated into sed/awk.

Closes #8600

* fix(docs): unblock CI for Docker basePath guide

Describe the build-time basePath marker as a sentinel file instead of a
fabricated env var, and replace the unsupported ```env fence with bash so
fumadocs/Shiki can compile DOCKER_GUIDE.md during DAST smoke.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(docker): add changelog fragment for #8615 basePath bundle patch

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
2026-07-27 19:07:58 -03:00

32 lines
1.2 KiB
JavaScript

/**
* Normalize OMNIROUTE_BASE_PATH for Next.js `basePath` and Docker sentinels.
*
* Rules mirror src/shared/services/modelSyncScheduler.ts::normalizeInternalBasePath
* so runtime self-fetches and the compiled bundle agree on the subpath shape.
*
* @param {string | undefined | null} value
* @returns {string} "" for root, otherwise "/segment" without trailing slash
*/
export function normalizeBasePath(value) {
const trimmed = typeof value === "string" ? value.trim() : "";
if (!trimmed || trimmed === "/") return "";
if (!trimmed.startsWith("/") || /[?#\\]/.test(trimmed)) return "";
const segments = trimmed.split("/").filter(Boolean);
if (segments.some((segment) => segment === "." || segment === "..")) return "";
return `/${segments.join("/")}`;
}
/**
* Prefix an application path with a normalized base path.
*
* @param {string} basePath normalized via normalizeBasePath
* @param {string} pathname must start with "/"
*/
export function joinBasePath(basePath, pathname) {
const pathPart = pathname.startsWith("/") ? pathname : `/${pathname}`;
if (!basePath) return pathPart;
if (pathPart === "/") return `${basePath}/`;
return `${basePath}${pathPart}`;
}