Configuration
Learn how to configure NEMO middleware
Configuration
NEMO offers flexible configuration options to organize your middleware functions.
Middlewares
Type: MiddlewareConfig
Chain type: "main"
The middlewares
object is a key-value pair where the key is the route path and the value is an array of middleware functions. Each middleware function is an async function that takes a single argument, request
, which is an object containing the request details.
Simple Middleware
The simplest form is a direct function assignment to a route pattern:
Middleware Arrays
You can assign an array of middleware functions to execute in sequence:
Nested Routes
NEMO supports nested route definitions with their own middleware:
When using nested routes, the parent route's middleware executes before any matching child route middleware.
Deep Nesting with Parameters
You can create deeply nested structures with URL parameters:
This structure handles routes like /shop/categories/electronics/products/laptop
with parameters accessible via event.params
.
Global Middlewares
Type: GlobalMiddlewareConfig
Global middleware functions are executed for all routes, regardless of the specific route configuration.
Before
Type: MiddlewareFunction | MiddlewareFunction[]
The before
middleware executes before any route-specific middleware:
After
Type: MiddlewareFunction | MiddlewareFunction[]
The after
middleware executes after all route-specific middleware:
Config object
Type: NemoConfig
The config
object is a key-value pair where the key is the configuration option and the value is the configuration value. The available configuration options are:
Prop | Type | Default |
---|---|---|
debug | boolean | false |
silent | boolean | false |
enableTiming | boolean | false |
errorHandler | ErrorHandler | undefined |
Example
Getting all of above informations together makes for us NEMO's full configuration representing all usable properites.
The createNEMO()
constructor is the entry point for the NEMO package. It allows you to create a middleware helper that can be used to define middleware functions for your Next.js application.