@hazeljs/config 0.7.9 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ export class DatabaseService {
|
|
|
88
88
|
connect() {
|
|
89
89
|
const dbUrl = this.configService.get('DATABASE_URL');
|
|
90
90
|
const port = this.configService.get('PORT');
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
console.log(`Connecting to database: ${dbUrl}`);
|
|
93
93
|
console.log(`Server will run on port: ${port}`);
|
|
94
94
|
}
|
|
@@ -102,18 +102,15 @@ export class DatabaseService {
|
|
|
102
102
|
```typescript
|
|
103
103
|
ConfigModule.forRoot({
|
|
104
104
|
schema: AppConfig,
|
|
105
|
-
envFilePath: [
|
|
106
|
-
'.env',
|
|
107
|
-
`.env.${process.env.NODE_ENV}`,
|
|
108
|
-
'.env.local',
|
|
109
|
-
],
|
|
105
|
+
envFilePath: ['.env', `.env.${process.env.NODE_ENV}`, '.env.local'],
|
|
110
106
|
validate: true,
|
|
111
|
-
})
|
|
107
|
+
});
|
|
112
108
|
```
|
|
113
109
|
|
|
114
110
|
### File Priority
|
|
115
111
|
|
|
116
112
|
Files are loaded in order, with later files overriding earlier ones:
|
|
113
|
+
|
|
117
114
|
1. `.env` - Base configuration
|
|
118
115
|
2. `.env.${NODE_ENV}` - Environment-specific
|
|
119
116
|
3. `.env.local` - Local overrides (gitignored)
|
|
@@ -171,7 +168,7 @@ export class AppConfig {
|
|
|
171
168
|
@MinLength(32, { message: 'JWT_SECRET must be at least 32 characters' })
|
|
172
169
|
JWT_SECRET: string;
|
|
173
170
|
|
|
174
|
-
@ValidateIf(o => o.NODE_ENV === 'production')
|
|
171
|
+
@ValidateIf((o) => o.NODE_ENV === 'production')
|
|
175
172
|
@IsString()
|
|
176
173
|
SSL_CERT_PATH: string;
|
|
177
174
|
}
|
|
@@ -329,10 +326,13 @@ ConfigModule.forRoot({
|
|
|
329
326
|
async () => {
|
|
330
327
|
// Load from database
|
|
331
328
|
const settings = await database.settings.findMany();
|
|
332
|
-
return settings.reduce(
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
329
|
+
return settings.reduce(
|
|
330
|
+
(acc, s) => ({
|
|
331
|
+
...acc,
|
|
332
|
+
[s.key]: s.value,
|
|
333
|
+
}),
|
|
334
|
+
{}
|
|
335
|
+
);
|
|
336
336
|
},
|
|
337
337
|
async () => {
|
|
338
338
|
// Load from API
|
|
@@ -340,7 +340,7 @@ ConfigModule.forRoot({
|
|
|
340
340
|
return await response.json();
|
|
341
341
|
},
|
|
342
342
|
],
|
|
343
|
-
})
|
|
343
|
+
});
|
|
344
344
|
```
|
|
345
345
|
|
|
346
346
|
## Configuration Service API
|
|
@@ -393,7 +393,7 @@ ConfigModule.forRoot({
|
|
|
393
393
|
allowUnknown: false,
|
|
394
394
|
abortEarly: false,
|
|
395
395
|
},
|
|
396
|
-
})
|
|
396
|
+
});
|
|
397
397
|
```
|
|
398
398
|
|
|
399
399
|
### 4. Use Type-Safe Access
|
|
@@ -411,7 +411,7 @@ const port = process.env.PORT; // string | undefined
|
|
|
411
411
|
```typescript
|
|
412
412
|
/**
|
|
413
413
|
* Application Configuration
|
|
414
|
-
*
|
|
414
|
+
*
|
|
415
415
|
* Required Environment Variables:
|
|
416
416
|
* - NODE_ENV: Application environment (development|production|test)
|
|
417
417
|
* - PORT: Server port number
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hazeljs/config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Configuration module for HazelJS framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@hazeljs/core": ">=0.2.0-beta.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "8b7685d1250c4622f25d83992f58e13a59bb3dba"
|
|
53
53
|
}
|