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

contentPath

string or string[]

Site-relative content path.

headers

Headers

Optional. Incoming headers. Draft Mode headers are added automatically when enabled.

locale

string

Optional. Active route locale; defaults through ENONIC_MAPPINGS.

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 siteKey where needed, to the guillotine() field.

Parameters

Name Type Description

contentApiUrl

string

Guillotine endpoint URL.

options

FetchOptions

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

apiUrl

string

Destination URL.

options

FetchOptions

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

query

string

Optional. Guillotine query. Defaults to the adapter’s static-path query.

countPerLocale

number

Optional. Maximum per locale. Default: 999.

Returns

Promise<ContentPathItem[]>.

fetchContentPathsForLocale

Returns content paths for one LocaleMapping.

Parameters

Name Type Description

mapping

LocaleMapping

Locale, project, and site to query.

query

string

Optional. Guillotine query.

count

number

Optional. Maximum results. Default: 999.

Returns

Promise<ContentPathItem[]>.

Classes

This entry point exports no classes.

Type Definitions

FetchContentResult

Name Type Description

data

Record<string, any> or null

Content-type query result.

common

Record<string, any> or null

Shared query result.

meta

MetaData

Runtime and editing context.

page

PageComponent or null

Normalized page component tree.

error

{code, message} or null

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.


Contents

Contents