Configuration
modules.config.ts
This file lists all active modules in your project:
import { authModule } from './modules/auth-module/src';
import { exampleModule } from './modules/example-module/src';
export const modules = [
authModule,
exampleModule,
];Module configuration
Since defineModule() returns a callable, you can pass configuration inline:
export const modules = [
authModule({
enabled: true,
features: {
routes: true,
apiRoutes: true,
middleware: true,
},
}),
exampleModule({ customOption: 'value' }),
];Base configuration
Every module accepts these base options:
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Enable or disable the entire module |
features.routes | boolean | true | Enable/disable page routes |
features.apiRoutes | boolean | true | Enable/disable API endpoints |
features.middleware | boolean | true | Enable/disable middleware |
When a feature is disabled, requests to those paths return 404 (routes) or 503 (API).
Global middleware
A module’s middleware is scoped to its basePath by default. To run it on every
request, set global: true in the module definition’s middleware block. See
Module Structure › Middleware for details. The
features.middleware toggle above still disables it regardless of global.
Runtime initialization
The next-modular.runtime.ts file bridges config and runtime:
import { configureModules } from 'next-modular';
import { modules } from './modules.config';
configureModules({ modules });
export { modules };This file is imported by the catch-all routes to ensure modules are registered before handling requests. configureModules() clears the registry and re-registers all modules from the config.
Debug logging
next-modular’s [next-modular] logs are off by default. Enable them with an
environment variable:
NEXT_MODULAR_DEBUG=true npm run devYou can also toggle it programmatically with setDebug(true).
Accessing module config at runtime
import { getModuleConfig } from 'next-modular';
const config = getModuleConfig<MyModuleConfig>('my-module');