fix(frontend): resolve API base URL at request time for production

Use same-origin /api in the browser so builds are not stuck with baked-in
localhost. Server-side fetches use INTERNAL_API_URL, NEXT_PUBLIC_API_URL, or
loopback. Centralize logic in lib/api-base.ts.

Made-with: Cursor
This commit is contained in:
Michilis
2026-04-01 19:52:54 +00:00
parent 76210db03d
commit 8cdf0231ce
7 changed files with 25 additions and 17 deletions

View File

@@ -1,12 +1,11 @@
import type { Metadata } from "next";
import BlogPostClient from "./BlogPostClient";
import { BlogPostingJsonLd, BreadcrumbJsonLd } from "@/components/public/JsonLd";
const apiUrl = process.env.NEXT_PUBLIC_API_URL || "http://localhost:4000/api";
import { apiUrl } from "@/lib/api-base";
async function fetchPost(slug: string) {
try {
const res = await fetch(`${apiUrl}/posts/${slug}`, {
const res = await fetch(apiUrl(`/posts/${slug}`), {
next: { revalidate: 300 },
});
if (!res.ok) return null;