Configuration object for the server layers.
Optional
additionalLayers?: Layer<any, any, never>[]An optional list of additional Layer
instances to be merged with the default server layers.
For example, you might want to pass a custom live implementation of a middleware.
Optional
serialization?: SerializationLayerA single Layer
instance representing the merged server infrastructure.
const authMiddlewareLayer = AuthMiddleware.Default;
const serverLayers = getServerLayers(authMiddlewareLayer, Layer.succeed(authMiddlewareLayer));
Constructs and returns a merged
Layer
composed of several essential server-side layers, along with any additional layers provided as arguments.This function is typically used to assemble the foundational infrastructure required for server-side effectful RPC (Remote Procedure Call) operations. It merges the following layers by default:
RpcSerialization.layerNdjson
: Provides NDJSON-based serialization for RPC communication.FetchHttpClient.layer
: Supplies an HTTP client implementation based on the Fetch API.HttpServer.layerContext
: Sets up the HTTP server context required for handling requests.additionalLayers
parameter.You can customize the following aspects:
serialization
property. Must be of type SerializationLayer.You should use these when you want to handle the RPC endpoints in Next.js Route Handlers.
NOTE: If you use a custom serialization layer, make sure it is compatible with the RPC server you are communicating with. This means, you most likely want to modify the createEffectRPC function invocation to use the same serialization layer!