mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
extend environment and use injected app config
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { APP_INITIALIZER, NgModule } from '@angular/core';
|
||||
import { BrowserModule, makeStateKey, TransferState } from '@angular/platform-browser';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { RouterModule, NoPreloading } from '@angular/router';
|
||||
import { REQUEST } from '@nguniversal/express-engine/tokens';
|
||||
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
@@ -30,9 +31,13 @@ import {
|
||||
} from '../../app/core/services/browser-hard-redirect.service';
|
||||
import { LocaleService } from '../../app/core/locale/locale.service';
|
||||
import { GoogleAnalyticsService } from '../../app/statistics/google-analytics.service';
|
||||
import { RouterModule, NoPreloading } from '@angular/router';
|
||||
import { AuthRequestService } from '../../app/core/auth/auth-request.service';
|
||||
import { BrowserAuthRequestService } from '../../app/core/auth/browser-auth-request.service';
|
||||
import { AppConfig, APP_CONFIG_STATE } from '../../config/app-config.interface';
|
||||
import { DefaultAppConfig } from '../../config/default-app-config';
|
||||
import { extendEnvironmentWithAppConfig } from '../../config/config.util';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
export const REQ_KEY = makeStateKey<string>('req');
|
||||
|
||||
@@ -54,12 +59,12 @@ export function getRequest(transferState: TransferState): any {
|
||||
// forRoot ensures the providers are only created once
|
||||
IdlePreloadModule.forRoot(),
|
||||
RouterModule.forRoot([], {
|
||||
// enableTracing: true,
|
||||
useHash: false,
|
||||
scrollPositionRestoration: 'enabled',
|
||||
anchorScrolling: 'enabled',
|
||||
preloadingStrategy: NoPreloading
|
||||
}),
|
||||
// enableTracing: true,
|
||||
useHash: false,
|
||||
scrollPositionRestoration: 'enabled',
|
||||
anchorScrolling: 'enabled',
|
||||
preloadingStrategy: NoPreloading
|
||||
}),
|
||||
StatisticsModule.forRoot(),
|
||||
Angulartics2RouterlessModule.forRoot(),
|
||||
BrowserAnimationsModule,
|
||||
@@ -74,6 +79,20 @@ export function getRequest(transferState: TransferState): any {
|
||||
AppModule
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: (transferState: TransferState) => {
|
||||
if (transferState.hasKey<AppConfig>(APP_CONFIG_STATE)) {
|
||||
const appConfig = transferState.get<AppConfig>(APP_CONFIG_STATE, new DefaultAppConfig());
|
||||
// extend environment with app config for browser
|
||||
extendEnvironmentWithAppConfig(environment, appConfig);
|
||||
}
|
||||
|
||||
return () => true;
|
||||
},
|
||||
deps: [TransferState],
|
||||
multi: true
|
||||
},
|
||||
{
|
||||
provide: REQUEST,
|
||||
useFactory: getRequest,
|
||||
|
@@ -1,38 +1,40 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||
import { APP_INITIALIZER, NgModule } from '@angular/core';
|
||||
import { BrowserModule, TransferState } from '@angular/platform-browser';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { ServerModule } from '@angular/platform-server';
|
||||
import { RouterModule } from '@angular/router';
|
||||
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
import { Angulartics2 } from 'angulartics2';
|
||||
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
||||
|
||||
import { AppComponent } from '../../app/app.component';
|
||||
|
||||
import { AppModule } from '../../app/app.module';
|
||||
import { DSpaceServerTransferStateModule } from '../transfer-state/dspace-server-transfer-state.module';
|
||||
import { DSpaceTransferState } from '../transfer-state/dspace-transfer-state.service';
|
||||
|
||||
import { TranslateJson5UniversalLoader } from '../../ngx-translate-loaders/translate-json5-universal.loader';
|
||||
import { CookieService } from '../../app/core/services/cookie.service';
|
||||
import { ServerCookieService } from '../../app/core/services/server-cookie.service';
|
||||
import { AuthService } from '../../app/core/auth/auth.service';
|
||||
import { ServerAuthService } from '../../app/core/auth/server-auth.service';
|
||||
|
||||
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
||||
import { AngularticsProviderMock } from '../../app/shared/mocks/angulartics-provider.service.mock';
|
||||
import { SubmissionService } from '../../app/submission/submission.service';
|
||||
import { ServerSubmissionService } from '../../app/submission/server-submission.service';
|
||||
import { Angulartics2DSpace } from '../../app/statistics/angulartics/dspace-provider';
|
||||
import { ServerLocaleService } from '../../app/core/locale/server-locale.service';
|
||||
import { LocaleService } from '../../app/core/locale/locale.service';
|
||||
import { HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||
import { ForwardClientIpInterceptor } from '../../app/core/forward-client-ip/forward-client-ip.interceptor';
|
||||
import { HardRedirectService } from '../../app/core/services/hard-redirect.service';
|
||||
import { ServerHardRedirectService } from '../../app/core/services/server-hard-redirect.service';
|
||||
import { Angulartics2 } from 'angulartics2';
|
||||
import { Angulartics2Mock } from '../../app/shared/mocks/angulartics2.service.mock';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { AuthRequestService } from '../../app/core/auth/auth-request.service';
|
||||
import { ServerAuthRequestService } from '../../app/core/auth/server-auth-request.service';
|
||||
import { AppConfig, APP_CONFIG_STATE } from '../../config/app-config.interface';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
export function createTranslateLoader() {
|
||||
return new TranslateJson5UniversalLoader('dist/server/assets/i18n/', '.json5');
|
||||
@@ -60,6 +62,16 @@ export function createTranslateLoader() {
|
||||
AppModule
|
||||
],
|
||||
providers: [
|
||||
// Initialize app config and extend environment
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: (transferState: TransferState) => {
|
||||
transferState.set<AppConfig>(APP_CONFIG_STATE, environment as AppConfig);
|
||||
return () => true;
|
||||
},
|
||||
deps: [TransferState],
|
||||
multi: true
|
||||
},
|
||||
{
|
||||
provide: Angulartics2,
|
||||
useClass: Angulartics2Mock
|
||||
|
Reference in New Issue
Block a user