This version (v0.7) has not been published to npm yet.
Skip to content

Reference / @getenginex/sdk-next/server / getEnginexServer

getEnginexServer() ​

getEnginexServer(options?): Promise<EnginexClient>

EngineX client for Server Components, Server Actions and Route Handlers of the App Router: one per request, with the tenant taken from the request headers and anonymous by default (it does not read cookies, does not renew the session).

  • Tenant: host → x-forwarded-host from headers(). x-original-host only counts with trustOriginalHost (it can come from the browser); resolveHost replaces everything.
  • Gateway: baseUrl or the ENGINEX_GATEWAY_URL environment variable (absolute URL).
  • Per request: memoized with React's cache(). Within the same request, calls with equal options return the same client (the tags compared by content, resolveHost and tokenStore by reference); different options, different clients. Different requests never share a client.
  • Next cache: next: { revalidate, tags } goes on every fetch.

Reading headers() makes the route dynamic, like any per-tenant data.

Parameters ​

options? ​

GetEnginexServerOptions = {}

Gateway, fetch cache, tenant discovery, tokens and language.

Returns ​

Promise<EnginexClient>

Promise of the current request's client.

Throws ​

CONFIGURATION_ERROR (rejected promise) without an absolute baseUrl or without a tenant in the request, before any fetch.

Example ​

ts
// app/page.tsx (Server Component)
import { getEnginexServer } from '@getenginex/sdk-next/server'

export default async function Page() {
  const enginex = await getEnginexServer({ next: { revalidate: 300, tags: ['config'] } })
  const config = await enginex.config.get()
  return <p>Currency: {config.defaultCurrency}</p>
}