File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed
_common/backend-initializer Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -8,18 +8,25 @@ import path from 'path';
88import { Logger } from '@nestjs/common' ;
99import { validateOrReject } from 'class-validator' ;
1010
11- export default async function configInitializer ( backendsPath : string ) {
11+ const backendsConfig : BackendConfigDto [ ] = [ ] ;
12+
13+ export default async function configInitializer ( backendsPath : string ) : Promise < BackendConfigDto [ ] > {
14+ /**
15+ * If backendsConfig is not empty, it cached in memory, return it
16+ */
17+ if ( backendsConfig . length ) return backendsConfig ;
18+
1219 const logger = new Logger ( configInitializer . name ) ;
1320 logger . log ( 'load backends config' ) ;
1421
15- const backendsConfig = [ ] ;
16- const crawler = new fdir ( ) . withBasePath ( ) . filter ( ( path ) => path . endsWith ( '.yml' ) ) ;
22+ const crawler = new fdir ( ) . withBasePath ( ) . filter ( ( path : string ) => path . endsWith ( '.yml' ) ) ;
1723 const files = crawler . crawl ( backendsPath ) . sync ( ) . sort ( ) ;
1824
1925 for await ( const file of files ) {
2026 logger . log ( 'Load ' + file ) ;
2127 const data = fs . readFileSync ( file , 'utf8' ) ;
2228 const config = YAML . parse ( data ) ;
29+
2330 try {
2431 config . path = path . dirname ( file ) ;
2532 const schema = plainToInstance ( BackendConfigDto , config ) ;
Original file line number Diff line number Diff line change 11import { NestFactory } from '@nestjs/core' ;
22import { AppModule } from './app.module' ;
33import { LogLevel } from '@nestjs/common' ;
4- import ConfigInstance from './config' ;
4+ import configInstance from './config' ;
55
66declare const module : any ;
77( async ( ) : Promise < void > => {
@@ -17,8 +17,8 @@ declare const module: any;
1717
1818async function setLogLevel ( ) : Promise < LogLevel [ ] > {
1919 let loggerOptions : LogLevel [ ] = [ 'error' , 'warn' , 'fatal' ] ;
20- const configInstance = await ConfigInstance ( ) ;
21- switch ( configInstance [ 'logLevel' ] ) {
20+ const config = await configInstance ( ) ;
21+ switch ( config [ 'logLevel' ] ) {
2222 case 'fatal' :
2323 loggerOptions = [ 'fatal' ] ;
2424 break ;
Original file line number Diff line number Diff line change 22 "compilerOptions" : {
33 "module" : " CommonJS" ,
44 "moduleResolution" : " Node" ,
5+ "lib" : [" ESNext" ],
56 "declaration" : true ,
67 "removeComments" : true ,
78 "skipLibCheck" : true ,
You can’t perform that action at this time.
0 commit comments