Reference / @getenginex/sdk-next/config / withEnginex
withEnginex()
Call Signature
withEnginex<
A,R>(config,options): (...args) =>Promise<WithEnginexConfig<Awaited<R>>>
Adds to next.config the rewrite that sends /api/:path* (and the other paths) to the gateway, as the players do by hand today. To use in next.config.ts (@getenginex/sdk-next/config is neither server nor client code; it has an ESM and a CJS build).
- Preserves the app's rewrites, as an array or as
{ beforeFiles, afterFiles, fallback }, from a sync or async function; the gateway's go after the app's (inafterFiles, in object format). - Does not duplicate: an app rewrite without a condition with the same
sourcewins, and applying it twice does not repeat anything. An app rewrite withhas/missingon the samesourcedoes not cover all requests: the gateway's goes after it. - Composes with other wrappers: accepts the config object or the function
(phase, ctx) => config(also async), and returns the same format. It does not change the object it receives.
The x-original-host the gateway uses to find the operator comes from the app's proxy.ts (see the getEnginexServer docs); this helper does not touch it.
Type Parameters
A
A extends unknown[]
R
R extends object | Promise<object>
Parameters
config
(...args) => R
The Next config, or the function that returns it.
options
Gateway URL and paths.
Returns
The config with rewrites replaced by an async function (or the function that returns it).
(...args) => Promise<WithEnginexConfig<Awaited<R>>>
Throws
CONFIGURATION_ERROR, at call time, without an absolute gatewayUrl or with a paths item that does not start with /.
Example
// next.config.ts
import type { NextConfig } from 'next'
import { withEnginex } from '@getenginex/sdk-next/config'
const nextConfig: NextConfig = { reactStrictMode: true }
export default withEnginex(nextConfig, {
gatewayUrl: process.env.NEXT_PUBLIC_API_URL!,
paths: ['/api/:path*', '/dev/:path*'],
})Call Signature
withEnginex<
C>(config,options):WithEnginexConfig<C>
Adds to next.config the rewrite that sends /api/:path* (and the other paths) to the gateway, as the players do by hand today. To use in next.config.ts (@getenginex/sdk-next/config is neither server nor client code; it has an ESM and a CJS build).
- Preserves the app's rewrites, as an array or as
{ beforeFiles, afterFiles, fallback }, from a sync or async function; the gateway's go after the app's (inafterFiles, in object format). - Does not duplicate: an app rewrite without a condition with the same
sourcewins, and applying it twice does not repeat anything. An app rewrite withhas/missingon the samesourcedoes not cover all requests: the gateway's goes after it. - Composes with other wrappers: accepts the config object or the function
(phase, ctx) => config(also async), and returns the same format. It does not change the object it receives.
The x-original-host the gateway uses to find the operator comes from the app's proxy.ts (see the getEnginexServer docs); this helper does not touch it.
Type Parameters
C
C extends object
Parameters
config
C
The Next config, or the function that returns it.
options
Gateway URL and paths.
Returns
The config with rewrites replaced by an async function (or the function that returns it).
Throws
CONFIGURATION_ERROR, at call time, without an absolute gatewayUrl or with a paths item that does not start with /.
Example
// next.config.ts
import type { NextConfig } from 'next'
import { withEnginex } from '@getenginex/sdk-next/config'
const nextConfig: NextConfig = { reactStrictMode: true }
export default withEnginex(nextConfig, {
gatewayUrl: process.env.NEXT_PUBLIC_API_URL!,
paths: ['/api/:path*', '/dev/:path*'],
})