Make imager URL absolute using NEXT_PUBLIC_APP_URL to avoid port issues
Local Build and Deploy / deploy (push) Successful in 53s
Local Build and Deploy / deploy (push) Successful in 53s
This commit is contained in:
1 parent
a5e085e04c
commit
ddb7e77877
5 files changed
+44
-12
No files matched your search
@@ -1,23 +1,22 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
getAvatarUrl,
|
||||
DEFAULT_IMAGER_URL,
|
||||
resolveImagerBase,
|
||||
resolveUpstreamBase,
|
||||
} from "./imager";
|
||||
|
||||
describe("resolveImagerBase", () => {
|
||||
it("defaults to the site's own /imaging endpoint", () => {
|
||||
expect(resolveImagerBase()).toBe(DEFAULT_IMAGER_URL);
|
||||
expect(resolveImagerBase("")).toBe(DEFAULT_IMAGER_URL);
|
||||
expect(resolveImagerBase(null)).toBe(DEFAULT_IMAGER_URL);
|
||||
it("defaults to /imaging when no public URL env is set", () => {
|
||||
expect(resolveImagerBase()).toBe("/imaging");
|
||||
expect(resolveImagerBase("")).toBe("/imaging");
|
||||
expect(resolveImagerBase(null)).toBe("/imaging");
|
||||
});
|
||||
|
||||
it("rejects the broken self-hosted proxy", () => {
|
||||
expect(resolveImagerBase("/api/imaging/avatar")).toBe(DEFAULT_IMAGER_URL);
|
||||
expect(resolveImagerBase("/api/imaging/avatar")).toBe("/imaging");
|
||||
expect(
|
||||
resolveImagerBase("https://www.epicnabbo.nl/api/imaging/avatar"),
|
||||
).toBe(DEFAULT_IMAGER_URL);
|
||||
).toBe("/imaging");
|
||||
});
|
||||
|
||||
it("accepts /imaging as a valid configured URL", () => {
|
||||
@@ -45,7 +44,7 @@ describe("getAvatarUrl", () => {
|
||||
headOnly: true,
|
||||
direction: 2,
|
||||
});
|
||||
expect(url.startsWith(`${DEFAULT_IMAGER_URL}?`)).toBe(true);
|
||||
expect(url.startsWith("/imaging?")).toBe(true);
|
||||
expect(url).toContain("figure=hr-115-42.hd-180-1");
|
||||
expect(url).toContain("size=l");
|
||||
expect(url).toContain("headonly=1");
|
||||
|
||||
+9
-3
@@ -10,8 +10,14 @@ export type { AvatarOptions } from "@/types/admin";
|
||||
|
||||
import type { AvatarOptions } from "@/types/admin";
|
||||
|
||||
/** Default public imager endpoint (relative — served by the site itself). */
|
||||
export const DEFAULT_IMAGER_URL = "/imaging";
|
||||
/** Build an absolute default imager URL from public env vars. */
|
||||
function defaultImagerUrl(): string {
|
||||
const pub = process.env.NEXT_PUBLIC_IMAGER_URL?.trim();
|
||||
if (pub && !pub.includes("/api/imaging/avatar")) return pub.replace(/\/+$/, "");
|
||||
const app = process.env.NEXT_PUBLIC_APP_URL?.trim();
|
||||
if (app) return `${app.replace(/\/+$/, "")}/imaging`;
|
||||
return "/imaging";
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the public-facing imager base URL.
|
||||
@@ -25,7 +31,7 @@ export function resolveImagerBase(configured?: string | null): string {
|
||||
|
||||
const v = (configured ?? "").trim();
|
||||
if (!v || v.includes("/api/imaging/avatar")) {
|
||||
return DEFAULT_IMAGER_URL;
|
||||
return defaultImagerUrl();
|
||||
}
|
||||
return v.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user