Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { ServerModule } from '@angular/platform-server';
import { PrebootModule } from 'preboot';
import { AppComponent } from './app.component';
import { AppModuleShared } from './app.module';
import { TransferHttpCacheModule, StateTransferInitializerModule } from '@nguniversal/common';
@NgModule({
bootstrap: [AppComponent],
imports: [
// Our Common AppModule
AppModuleShared,
ServerModule,
PrebootModule.withConfig({ appRoot: 'app-root' }),
NoopAnimationsModule,
TransferHttpCacheModule, // still needs fixes for 5.0
// Leave this commented out for now, as it breaks Server-renders
// Looking into fixes for this! - @MarkPieszak
// StateTransferInitializerModule // <-- broken for the time-being with ASP.NET
]
})
export class AppModule {
constructor() {}
}
import { AppComponent } from './app.component';
import { AppModuleShared } from './app.module';
export function getOriginUrl() {
return window.location.origin;
}
export function getRequest() {
// the Request object only lives on the server
return { cookie: document.cookie };
}
@NgModule({
bootstrap: [AppComponent],
imports: [
PrebootModule.withConfig({ appRoot: 'app-root' }),
BrowserAnimationsModule,
// Our Common AppModule
AppModuleShared
],
providers: [
{
// We need this for our Http calls since they'll be using an ORIGIN_URL provided in main.server
// (Also remember the Server requires Absolute URLs)
provide: ORIGIN_URL,
useFactory: getOriginUrl
},
{
// The server provides these in main.server
provide: REQUEST,
useFactory: getRequest
BrowserTransferStateModule,
} from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { PrebootModule } from 'preboot';
import { NgAisModule } from 'angular-instantsearch';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule.withServerTransition({ appId: 'my-app' }),
PrebootModule.withConfig({ appRoot: 'app-root' }),
HttpClientModule,
BrowserTransferStateModule,
NgAisModule.forRoot(),
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
`,
})
export class AppComponent {
platform: string;
constructor( @Inject(PLATFORM_ID) public _platform: string) {
this.platform = isPlatformBrowser(_platform) ? 'client view' : 'server view';
}
}
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule.withServerTransition({ appId: 'foo' }),
PrebootModule.withConfig({ appRoot: 'app-root' })
],
bootstrap: [AppComponent]
})
export class AppBrowserModule { }
@NgModule({
imports: [
AppBrowserModule,
ServerModule
],
bootstrap: [AppComponent]
})
export class AppServerModule { }
}
/**
* Marks an class as an NgModule so it could be configured
*/
@NgModule({
bootstrap: [AppComponent],
declarations: [AppComponent],
imports: [
AppRoutingModule,
BrowserModule.withServerTransition({ appId: 'serverApp' }),
BrowserTransferStateModule,
EffectsModule.forRoot([GoogleAnalyticsEffects, RouterEffects]),
ErrorModule,
HttpClientModule,
PrebootModule.withConfig({ appRoot: 'app-root' }),
StoreModule.forRoot(
{
applicationState: fromApplication.Applicationreducer,
routerState: routerReducer,
},
{ initialState: getInitialState },
),
StoreDevtoolsModule.instrument(),
ServiceWorkerModule.register('ngsw-worker.js', {
enabled: environment.production,
}),
TranslateModule.forRoot({
loader: {
deps: [HttpClient],
provide: TranslateLoader,
useFactory: createTranslateLoader,