mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
* 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>
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import {
|
|
patchBasePathLiterals,
|
|
patchJsonManifestFile,
|
|
patchStandaloneBasePath,
|
|
} from "../../scripts/docker/patch-standalone-base-path.mjs";
|
|
|
|
test("patchBasePathLiterals rewrites empty basePath literals", () => {
|
|
const input = 'const cfg={basePath:"",assetPrefix:void 0};"basePath":""';
|
|
const output = patchBasePathLiterals(input, "/omniroute");
|
|
assert.match(output, /basePath:"\/omniroute"/);
|
|
assert.match(output, /"basePath":"\/omniroute"/);
|
|
});
|
|
|
|
test("patchJsonManifestFile updates nested basePath fields", () => {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-basepath-"));
|
|
const filePath = path.join(dir, "routes-manifest.json");
|
|
fs.writeFileSync(
|
|
filePath,
|
|
JSON.stringify({ basePath: "", nested: { basePath: "" } }, null, 2)
|
|
);
|
|
assert.equal(patchJsonManifestFile(filePath, "/omniroute"), true);
|
|
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
assert.equal(parsed.basePath, "/omniroute");
|
|
assert.equal(parsed.nested.basePath, "/omniroute");
|
|
});
|
|
|
|
test("patchStandaloneBasePath rewrites a root-path standalone tree", () => {
|
|
const appRoot = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-standalone-"));
|
|
const distRoot = path.join(appRoot, ".build", "next");
|
|
fs.mkdirSync(path.join(distRoot, "server"), { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(distRoot, "routes-manifest.json"),
|
|
JSON.stringify({ basePath: "" })
|
|
);
|
|
fs.writeFileSync(
|
|
path.join(distRoot, "server", "chunk.js"),
|
|
'export const config={basePath:""};'
|
|
);
|
|
fs.writeFileSync(path.join(appRoot, "BUILD_OMNIROUTE_BASE_PATH"), "\n");
|
|
|
|
const result = patchStandaloneBasePath({
|
|
appRoot,
|
|
fromBasePath: "",
|
|
toBasePath: "/omniroute",
|
|
});
|
|
|
|
assert.equal(result.changed, true);
|
|
assert.equal(
|
|
JSON.parse(fs.readFileSync(path.join(distRoot, "routes-manifest.json"), "utf8")).basePath,
|
|
"/omniroute"
|
|
);
|
|
assert.match(fs.readFileSync(path.join(distRoot, "server", "chunk.js"), "utf8"), /\/omniroute/);
|
|
});
|
|
|
|
test("patchStandaloneBasePath rejects mismatched non-root builds", () => {
|
|
assert.throws(
|
|
() =>
|
|
patchStandaloneBasePath({
|
|
appRoot: process.cwd(),
|
|
fromBasePath: "/custom",
|
|
toBasePath: "/omniroute",
|
|
}),
|
|
/does not match the image build/
|
|
);
|
|
});
|