Server API
Contents
Import these functions from @enonic/nextjs-adapter/server. They depend on server-side Next.js and network APIs and must not enter client bundles.
Usage
import {
fetchContent,
fetchContentPathsForAllLocales,
fetchGuillotine
} from '@enonic/nextjs-adapter/server';
Functions
fetchContent
Fetches content metadata and registered component data, builds the page tree, and calculates runtime metadata.
Parameters
fetchContent() takes a single context object with these properties:
| Name | Type | Description |
|---|---|---|
|
|
|
Site-relative content path. |
|
|
|
Optional. Incoming headers. Draft Mode headers are added automatically when enabled. |
|
|
|
Optional. Active route locale; defaults through |
Returns
Promise<FetchContentResult>.
Example
const result = await fetchContent({
locale: 'en',
contentPath: ['news', 'launch']
});
fetchGuillotine
Sends a GraphQL request to Guillotine, minifies the query, and normalizes GraphQL and transport errors into a GuillotineResult. The query must pass project and branch, and scopeKey where needed, to the guillotine() field.
Parameters
| Name | Type | Description |
|---|---|---|
|
|
|
Guillotine endpoint URL. |
|
|
Optional. Request body, headers, cache, and Next.js revalidation options. |
Returns
Promise<GuillotineResult>.
fetchFromApi
Low-level JSON request used by fetchGuillotine(). It applies JSON headers and throws structured errors for network, HTTP, empty, or non-JSON responses.
Parameters
| Name | Type | Description |
|---|---|---|
|
|
|
Destination URL. |
|
|
Optional. Fetch and Next.js caching options. |
Returns
Promise<GuillotineResponseJson>.
fetchContentPathsForAllLocales
Returns content paths for every configured locale, normally for generateStaticParams().
Parameters
| Name | Type | Description |
|---|---|---|
|
|
|
Optional. Guillotine query. Defaults to the adapter’s static-path query. |
|
|
|
Optional. Maximum per locale. Default: |
Returns
Promise<ContentPathItem[]>.
fetchContentPathsForLocale
Returns content paths for one LocaleMapping.
Parameters
| Name | Type | Description |
|---|---|---|
|
|
Locale, project, and site to query. |
|
|
|
|
Optional. Guillotine query. |
|
|
|
Optional. Maximum results. Default: |
Returns
Promise<ContentPathItem[]>.
proxyMedia
Streams authenticated media through Next.js while Draft Mode is active. The starter mounts this handler at /api/media; see Draft media proxy for URL composition and published-media behavior.
The handler accepts GET and HEAD requests for XP image and attachment endpoints, forwards range headers, and streams the upstream response. It requires the editor’s XP session in the jsessionid request header or cookie. Draft Mode alone does not authenticate the request.
Upstream fetches use cache: 'no-store', and streamed responses have Cache-Control: private, no-store. Disable caching for the entire route in your delivery infrastructure, including error responses.
Parameters
| Name | Type | Description |
|---|---|---|
|
|
|
Incoming media request, including its path, query string, and session credentials. |
|
|
|
Optional. Handler options described below. |
The options object has these properties:
| Name | Type | Description |
|---|---|---|
|
|
|
Optional. Route prefix to strip. Defaults to |
Returns
Promise<Response>. Returns 404 when Draft Mode is disabled and 401 when no XP session is supplied. Otherwise, the upstream response determines access and status.
Example
The starter’s src/app/api/media/[…path]/route.ts delegates requests to the adapter:
import {proxyMedia} from '@enonic/nextjs-adapter/server';
export function GET(request: Request) {
return proxyMedia(request);
}
export const HEAD = GET;
Classes
This entry point exports no classes.
Type Definitions
FetchContentResult
| Name | Type | Description |
|---|---|---|
|
|
|
Content-type query result. |
|
|
|
Shared query result. |
|
|
Runtime and editing context. |
|
|
|
|
Normalized page component tree. |
|
|
|
Optional. Structured failure. |
FetchOptions
Standard RequestInit options with a JSON body containing query and variables, plus Next.js revalidate and tags options.
ContentPathItem
Contains contentPath: string[] and locale: string for one statically generated route.
Constants
This entry point exports no constants. Shared constants are available from the package root.