feat: implement environment variable validation with class-validator and class-transformer #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces improvements to the configuration and validation of environment variables within the application.
Previously, validation was performed by comparing the
.env.development.example
file with the currently set environment variables. Now, the validation process has been enhanced by leveraging theclass-validator
andclass-transformer
libraries for a more robust and scalable approach.The key updates include the implementation of a new validation mechanism for environment variables, the removal of outdated validation logic in the
AppModule
, and the reorganization of imports for better maintainability.Configuration and Validation Enhancements:
New
EnvironmentVariables
Class: Added a dedicated class to define validation rules for environment variables usingclass-validator
andclass-transformer
. This ensures that all required variables are present and properly formatted.(File:
server/src/config/EnvironmentVariables.ts
)validate
Function: Introduced a function that uses theplainToInstance
method to transform and validate the environment variables. This function throws an error if any required variables are missing or incorrectly formatted.(File:
server/src/config/EnvironmentVariables.ts
)Codebase Simplification:
AppModule
constructor that manually validated environment variables. The new validation function now handles this process, streamlining the codebase.