getTenantBackend
getTenantBackend resolves the backend API base URL for the current tenant in a multi-tenant deployment. Used in server components and API routes to construct fully-qualified API URLs.
Import
import { getTenantBackend } from "@phpcreation/frontend-crud-react-nextjs-bundle/utils/getTenantBackend";Usage
import { getTenantBackend } from "...";
export default async function InvoicesPage() {
const backendUrl = await getTenantBackend();
const invoices = await fetch(`${backendUrl}/api/invoices`).then(r => r.json());
return <InvoiceListing data={invoices} />;
}How It Works
Reads the current tenant identifier from the request headers or session cookie, then looks up the corresponding backend URL from the tenant registry (environment config or remote registry).
Returns
Promise<string> — the base URL of the current tenant’s backend API (e.g., https://tenant1.api.example.com).
This is a server-side utility only. Do not import in client components — it will fail at build time.
Related
Last updated on