From b149cf2d772d930b23eea20f1fe9b8048d6000a0 Mon Sep 17 00:00:00 2001 From: William Welling <8352733+wwelling@users.noreply.github.com> Date: Wed, 16 Feb 2022 13:43:48 -0600 Subject: [PATCH] afford production disable preboot --- README.md | 19 +++++++++++++++++-- src/config/app-config.interface.ts | 2 -- src/config/build-config.interface.ts | 6 ++++++ src/config/default-app-config.ts | 8 -------- src/environments/.gitignore | 5 +++++ src/environments/environment.production.ts | 4 ++-- src/environments/environment.test.ts | 4 ++-- src/environments/environment.ts | 4 ++-- src/main.browser.ts | 4 +++- 9 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 src/config/build-config.interface.ts create mode 100644 src/environments/.gitignore diff --git a/README.md b/README.md index 74010f3c5c..e4260ae67f 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Installing ### Configuring -Default configuration file is located in `config/` folder. +Default runtime configuration file is located in `config/` folder. These configurations can be changed without rebuilding the distribution. To override the default configuration values, create local files that override the parameters you need to change. You can use `config.example.yml` as a starting point. @@ -167,6 +167,22 @@ These configuration sources are collected **at run time**, and written to `dist/ The configuration file can be externalized by using environment variable `DSPACE_APP_CONFIG_PATH`. +#### Buildtime Configuring + +Buildtime configuration must defined before build in order to include in transpiled JavaScript. This is primarily for the server. These settings can be found under `src/environment/` folder. + +To override the default configuration values for development, create local file that override the build time parameters you need to change. + +- Create a new `environment.(dev or development).ts` file in `src/environment/` for a `development` environment; + +If needing to update default configurations values for production, update local file that override the build time parameters you need to change. + +- Update `environment.production.ts` file in `src/environment/` for a `production` environment; + +The environment object is provided for use as import in code and is extended with he runtime configuration on bootstrap of the application. + +> Take caution moving runtime configs into the buildtime configuration. They will be overwritten by what is defined in the runtime config on bootstrap. + #### Using environment variables in code To use environment variables in a UI component, use: @@ -183,7 +199,6 @@ or import { environment } from '../environment.ts'; ``` - Running the app --------------- diff --git a/src/config/app-config.interface.ts b/src/config/app-config.interface.ts index 62d0be7216..121e80cd74 100644 --- a/src/config/app-config.interface.ts +++ b/src/config/app-config.interface.ts @@ -3,7 +3,6 @@ import { makeStateKey } from '@angular/platform-browser'; import { Config } from './config.interface'; import { ServerConfig } from './server-config.interface'; import { CacheConfig } from './cache-config.interface'; -import { UniversalConfig } from './universal-config.interface'; import { INotificationBoardOptions } from './notifications-config.interfaces'; import { SubmissionConfig } from './submission-config.interface'; import { FormConfig } from './form-config.interfaces'; @@ -25,7 +24,6 @@ interface AppConfig extends Config { form: FormConfig; notifications: INotificationBoardOptions; submission: SubmissionConfig; - universal: UniversalConfig; debug: boolean; defaultLanguage: string; languages: LangConfig[]; diff --git a/src/config/build-config.interface.ts b/src/config/build-config.interface.ts new file mode 100644 index 0000000000..beb8097c9e --- /dev/null +++ b/src/config/build-config.interface.ts @@ -0,0 +1,6 @@ +import { AppConfig } from './app-config.interface'; +import { UniversalConfig } from './universal-config.interface'; + +export interface BuildConfig extends AppConfig { + universal: UniversalConfig; +} diff --git a/src/config/default-app-config.ts b/src/config/default-app-config.ts index df9bbe9369..263cfa0cdd 100644 --- a/src/config/default-app-config.ts +++ b/src/config/default-app-config.ts @@ -14,18 +14,10 @@ import { ServerConfig } from './server-config.interface'; import { SubmissionConfig } from './submission-config.interface'; import { ThemeConfig } from './theme.model'; import { UIServerConfig } from './ui-server-config.interface'; -import { UniversalConfig } from './universal-config.interface'; export class DefaultAppConfig implements AppConfig { production = false; - // Angular Universal settings - universal: UniversalConfig = { - preboot: true, - async: true, - time: false - }; - // NOTE: will log all redux actions and transfers in console debug = false; diff --git a/src/environments/.gitignore b/src/environments/.gitignore new file mode 100644 index 0000000000..03f1bde6f9 --- /dev/null +++ b/src/environments/.gitignore @@ -0,0 +1,5 @@ +environment.*.ts + +!environment.production.ts +!environment.test.ts +!environment.ts diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index 85c0f8fddc..09b5f19ade 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -1,6 +1,6 @@ -import { AppConfig } from '../config/app-config.interface'; +import { BuildConfig } from '../config/build-config.interface'; -export const environment: Partial = { +export const environment: Partial = { production: true, // Angular Universal settings diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index f8a3248837..1cbdca762e 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -1,9 +1,9 @@ // This configuration is only used for unit tests, end-to-end tests use environment.production.ts +import { BuildConfig } from 'src/config/build-config.interface'; import { RestRequestMethod } from '../app/core/data/rest-request-method'; import { NotificationAnimationsType } from '../app/shared/notifications/models/notification-animations-type'; -import { AppConfig } from '../config/app-config.interface'; -export const environment: AppConfig = { +export const environment: BuildConfig = { production: false, // Angular Universal settings diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 90eecac900..a64ccf2608 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -3,9 +3,9 @@ // `ng test --configuration test` replaces `environment.ts` with `environment.test.ts`. // The list of file replacements can be found in `angular.json`. -import { AppConfig } from '../config/app-config.interface'; +import { BuildConfig } from '../config/build-config.interface'; -export const environment: Partial = { +export const environment: Partial = { production: false, // Angular Universal settings diff --git a/src/main.browser.ts b/src/main.browser.ts index de4276ea93..433ed31298 100644 --- a/src/main.browser.ts +++ b/src/main.browser.ts @@ -30,7 +30,9 @@ const main = () => { if (environment.production) { enableProdMode(); + } + if (hasValue(environment.universal) && environment.universal.preboot) { return bootstrap(); } else { @@ -47,7 +49,7 @@ const main = () => { }; // support async tag or hmr -if (hasValue(environment.universal) && environment.universal.preboot === false) { +if (hasValue(environment.universal) && !environment.universal.preboot) { main(); } else { document.addEventListener('DOMContentLoaded', main);