From 94d64535d9e2664044720bb3f467ba456883fbd6 Mon Sep 17 00:00:00 2001 From: Mohammadreza Berneti Date: Sat, 17 Aug 2019 00:19:56 +0430 Subject: [PATCH 1/2] fixed entities path bug of the connection in the dev mode --- src/config.ts | 8 +++++++- src/server.ts | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/config.ts b/src/config.ts index 2d8e94a..03541ec 100644 --- a/src/config.ts +++ b/src/config.ts @@ -8,14 +8,20 @@ export interface IConfig { dbsslconn: boolean; jwtSecret: string; databaseUrl: string; + dbEntitiesPath: (Function | string)[]; } +const isInDevelompentMode = process.env.NODE_ENV == 'development'; + const config: IConfig = { port: +process.env.PORT || 3000, debugLogging: process.env.NODE_ENV == 'development', dbsslconn: process.env.NODE_ENV != 'development', jwtSecret: process.env.JWT_SECRET || 'your-secret-whatever', - databaseUrl: process.env.DATABASE_URL || 'postgres://user:pass@localhost:5432/apidb' + databaseUrl: process.env.DATABASE_URL || 'postgres://user:pass@localhost:5432/apidb', + dbEntitiesPath: [ + (isInDevelompentMode && 'dist/entity/**/*.js') || 'src/entity/**/*.ts' + ] }; export { config }; \ No newline at end of file diff --git a/src/server.ts b/src/server.ts index 42d15f9..3e31dd0 100644 --- a/src/server.ts +++ b/src/server.ts @@ -28,9 +28,7 @@ createConnection({ database: connectionOptions.database, synchronize: true, logging: false, - entities: [ - 'dist/entity/**/*.js' - ], + entities: config.dbEntitiesPath, extra: { ssl: config.dbsslconn, // if not development, will use SSL } From 1d7b204d26d67a76f1320f9d8a2b9609a6ead430 Mon Sep 17 00:00:00 2001 From: "Aviles, Javier" Date: Thu, 12 Sep 2019 21:03:34 +0200 Subject: [PATCH 2/2] Prod should always use js not ts; small refactoring --- src/config.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config.ts b/src/config.ts index 03541ec..31a72fa 100644 --- a/src/config.ts +++ b/src/config.ts @@ -11,16 +11,16 @@ export interface IConfig { dbEntitiesPath: (Function | string)[]; } -const isInDevelompentMode = process.env.NODE_ENV == 'development'; +const isDevMode = process.env.NODE_ENV == 'development'; const config: IConfig = { port: +process.env.PORT || 3000, - debugLogging: process.env.NODE_ENV == 'development', - dbsslconn: process.env.NODE_ENV != 'development', + debugLogging: isDevMode, + dbsslconn: !isDevMode, jwtSecret: process.env.JWT_SECRET || 'your-secret-whatever', databaseUrl: process.env.DATABASE_URL || 'postgres://user:pass@localhost:5432/apidb', dbEntitiesPath: [ - (isInDevelompentMode && 'dist/entity/**/*.js') || 'src/entity/**/*.ts' + ('dist/entity/**/*.js') || (isDevMode && 'src/entity/**/*.ts') ] };