|
1 |
| -import * as fs from 'fs'; |
2 |
| - |
3 | 1 | import { Logger, Module } from '@nestjs/common';
|
4 | 2 | import { ConfigModule, ConfigService } from '@nestjs/config';
|
5 | 3 | import { MongooseModule, MongooseModuleFactoryOptions } from '@nestjs/mongoose';
|
6 | 4 |
|
| 5 | +import { validate } from 'class-validator'; |
7 | 6 | import { AuthModule } from './auth/auth.module';
|
8 | 7 | import { FileModule } from './file/file.module';
|
9 | 8 | import { ParseTokenPipe } from './parseToken';
|
10 |
| -import { SongModule } from './song/song.module'; |
11 | 9 | import { SongBrowserModule } from './song-browser/song-browser.module';
|
| 10 | +import { SongModule } from './song/song.module'; |
12 | 11 | import { UserModule } from './user/user.module';
|
13 | 12 |
|
14 | 13 | @Module({
|
15 | 14 | imports: [
|
16 | 15 | ConfigModule.forRoot({
|
17 | 16 | isGlobal: true,
|
18 | 17 | envFilePath: ['.env.development', '.env.production'],
|
| 18 | + validate: validate, |
19 | 19 | }),
|
20 | 20 | //DatabaseModule,
|
21 | 21 | MongooseModule.forRootAsync({
|
@@ -44,46 +44,4 @@ import { UserModule } from './user/user.module';
|
44 | 44 | providers: [ParseTokenPipe],
|
45 | 45 | exports: [ParseTokenPipe],
|
46 | 46 | })
|
47 |
| -export class AppModule { |
48 |
| - private readonly logger = new Logger(AppModule.name); |
49 |
| - constructor(private readonly configService: ConfigService) { |
50 |
| - // read .env.development.example file |
51 |
| - const file = '.env.development.example'; |
52 |
| - const encoding = 'utf8'; |
53 |
| - const fileData = fs.readFileSync(file, encoding); |
54 |
| - |
55 |
| - const variableToIgnore = ['APP_DOMAIN', 'NODE_ENV', 'WHITELISTED_USERS']; |
56 |
| - |
57 |
| - const variables = fileData |
58 |
| - .split('\n') |
59 |
| - // trim whitespace |
60 |
| - .map((line) => line.trim()) |
61 |
| - // remove empty lines |
62 |
| - .filter((line) => line.length > 0) |
63 |
| - // get variable names |
64 |
| - .map((line) => line.split('=')[0]) |
65 |
| - // remove variables that are not in the .env.development.example file |
66 |
| - .filter((variable) => !variableToIgnore.includes(variable)); |
67 |
| - |
68 |
| - this.logger.warn(`Ignoring variables: ${variableToIgnore.join(', ')}`); |
69 |
| - this.logger.warn(`Checking variables: ${variables.join(', ')}`); |
70 |
| - |
71 |
| - let isMissing = false; |
72 |
| - |
73 |
| - for (const variable of variables) { |
74 |
| - const value = this.configService.get(variable); |
75 |
| - |
76 |
| - if (!value) { |
77 |
| - this.logger.error( |
78 |
| - `Missing environment variable ${variable} in env vars}`, |
79 |
| - ); |
80 |
| - |
81 |
| - isMissing = true; |
82 |
| - } |
83 |
| - } |
84 |
| - |
85 |
| - if (isMissing) { |
86 |
| - throw new Error('Missing environment variables in env vars file'); |
87 |
| - } |
88 |
| - } |
89 |
| -} |
| 47 | +export class AppModule {} |
0 commit comments