Skip to main content

Overview

The global configuration allows you to set default options that apply to all CRUD controllers in your application. This helps maintain consistency and reduces repetition across your codebase.
Global configuration must be loaded before importing your AppModule. This ensures that all controllers inherit the correct settings.

Basic Setup

Load global configuration in your main.ts file:
main.ts

Configuration Options

Query Options

Control query behavior across all endpoints:

Query Parameters

Routes Options

Configure which routes are available by default:
You can override global route settings in individual controllers using the @Crud() decorator.

Auth Options

Set global authentication property:
This specifies the request property where the authenticated user object is stored (e.g., req.user).

Query Parser Options

Customize query string parsing:

Serialization Options

Disable serialization globally for specific operations:
Setting serialization to false globally will disable DTOs for all controllers unless explicitly overridden.

Params Options

Define global parameter configurations:

Complete Example

Here’s a comprehensive global configuration:
main.ts

Override in Controllers

Global settings can be overridden in individual controllers:
users.controller.ts

Best Practices

1

Load Early

Always load global configuration before importing AppModule to ensure all controllers use the settings.
2

Set Sensible Defaults

Configure reasonable default values that work for most of your application.
3

Document Overrides

Clearly document when and why you override global settings in specific controllers.
4

Consider Security

Set appropriate maxLimit values to prevent abuse of your API.