Files
OmniRoute/scripts/build/write-build-base-path.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

43 lines
1.4 KiB
JavaScript

#!/usr/bin/env node
/**
* Writes BUILD_OMNIROUTE_BASE_PATH into the standalone bundle so container start
* can compare the baked Next.js basePath against OMNIROUTE_BASE_PATH.
*/
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { normalizeBasePath } from "./normalizeBasePath.mjs";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(__dirname, "..", "..");
const NEXT_DIST = process.env.NEXT_DIST_DIR || ".build/next";
function writeSentinel(targetDir) {
const basePath = normalizeBasePath(process.env.OMNIROUTE_BASE_PATH);
const sentinel = path.join(targetDir, "BUILD_OMNIROUTE_BASE_PATH");
fs.writeFileSync(sentinel, `${basePath}\n`);
return { basePath, sentinel };
}
const standaloneDir = path.join(ROOT, NEXT_DIST, "standalone");
if (!fs.existsSync(standaloneDir)) {
console.error(
`[write-build-base-path] FATAL: standalone dir not found: ${standaloneDir}\n` +
" Run `npm run build` first."
);
process.exit(1);
}
const { basePath, sentinel } = writeSentinel(standaloneDir);
console.log(
`[write-build-base-path] Recorded basePath ${basePath || "(root)"} -> ${path.relative(ROOT, sentinel)}`
);
const distDir = path.join(ROOT, "dist");
if (fs.existsSync(distDir)) {
const distSentinel = writeSentinel(distDir).sentinel;
console.log(`[write-build-base-path] Recorded basePath -> ${path.relative(ROOT, distSentinel)}`);
}