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 yourmain.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:Auth Options
Set global authentication property:req.user).
Query Parser Options
Customize query string parsing:Serialization Options
Disable serialization globally for specific operations: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.Related Resources
- Authentication - Configure authentication and authorization
- Serialization - Control response serialization
- Caching - Configure response caching