feat: Serve react app through express server

This commit is contained in:
Faruk AYDIN
2022-02-23 21:24:21 +03:00
committed by Ömer Faruk Aydın
parent d139eb8c06
commit 654e868a23
7 changed files with 55 additions and 24 deletions

View File

@@ -2,37 +2,46 @@ import * as dotenv from 'dotenv';
dotenv.config();
type AppConfig = {
host: string,
protocol: string
port: string,
webAppUrl: string,
appEnv: string,
postgresDatabase: string,
postgresPort: number,
postgresHost: string,
postgresUsername: string,
postgresPassword: string,
postgresEnableSsl: boolean,
baseUrl?: string,
encryptionKey: string
}
host: string;
protocol: string;
port: string;
webAppUrl?: string;
appEnv: string;
postgresDatabase: string;
postgresPort: number;
postgresHost: string;
postgresUsername: string;
postgresPassword: string;
postgresEnableSsl: boolean;
baseUrl?: string;
encryptionKey: string;
serveWebAppSeparately: boolean;
};
const appConfig: AppConfig = {
host: process.env.HOST || 'localhost',
protocol: process.env.PROTOCOL || 'http',
port: process.env.PORT || '3000',
webAppUrl: process.env.WEB_APP_URL || 'https://localhost:3001',
appEnv: process.env.APP_ENV || 'development',
postgresDatabase: process.env.POSTGRES_DATABASE || 'automatisch_development',
postgresPort: parseInt(process.env.POSTGRES_PORT) || 5432,
postgresHost: process.env.POSTGRES_HOST || 'localhost',
postgresUsername: process.env.POSTGRES_USERNAME || 'automatish_development_user',
postgresUsername:
process.env.POSTGRES_USERNAME || 'automatish_development_user',
postgresPassword: process.env.POSTGRES_PASSWORD,
postgresEnableSsl: process.env.POSTGRES_ENABLE_SSL === 'true' ? true : false,
encryptionKey: process.env.ENCRYPTION_KEY
encryptionKey: process.env.ENCRYPTION_KEY,
serveWebAppSeparately:
process.env.SERVE_WEB_APP_SEPARATELY === 'true' ? true : false,
};
if (appConfig.serveWebAppSeparately) {
appConfig.webAppUrl = process.env.WEB_APP_URL || 'http://localhost:3001';
} else {
appConfig.webAppUrl = `${appConfig.protocol}://${appConfig.host}:${appConfig.port}`;
}
if(!appConfig.encryptionKey) {
if (!appConfig.encryptionKey) {
throw new Error('ENCRYPTION_KEY environment variable needs to be set!');
}