2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 12:08:49 -07:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 09:47:54 -07:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2017-03-13 17:31:03 -07:00
|
|
|
import {ɵAnimationEngine} from '@angular/animations/browser';
|
2020-04-13 16:40:21 -07:00
|
|
|
import {DOCUMENT, PlatformLocation, ViewportScroller, ɵgetDOM as getDOM, ɵNullViewportScroller as NullViewportScroller, ɵPLATFORM_SERVER_ID as PLATFORM_SERVER_ID} from '@angular/common';
|
2017-03-22 17:13:24 -07:00
|
|
|
import {HttpClientModule} from '@angular/common/http';
|
2020-04-13 16:40:21 -07:00
|
|
|
import {createPlatformFactory, Injector, NgModule, NgZone, Optional, PLATFORM_ID, PLATFORM_INITIALIZER, platformCore, PlatformRef, Provider, RendererFactory2, StaticProvider, Testability, ɵALLOW_MULTIPLE_PLATFORMS as ALLOW_MULTIPLE_PLATFORMS, ɵsetDocument} from '@angular/core';
|
2019-08-22 19:16:25 -07:00
|
|
|
import {BrowserModule, EVENT_MANAGER_PLUGINS, ɵSharedStylesHost as SharedStylesHost} from '@angular/platform-browser';
|
2017-08-16 09:00:03 -07:00
|
|
|
import {ɵplatformCoreDynamic as platformCoreDynamic} from '@angular/platform-browser-dynamic';
|
2017-03-13 17:31:03 -07:00
|
|
|
import {NoopAnimationsModule, ɵAnimationRendererFactory} from '@angular/platform-browser/animations';
|
2017-02-22 16:49:46 -08:00
|
|
|
|
2017-08-08 02:17:40 -07:00
|
|
|
import {DominoAdapter, parseDocument} from './domino_adapter';
|
2017-02-10 17:00:27 -08:00
|
|
|
import {SERVER_HTTP_PROVIDERS} from './http';
|
2017-02-09 14:10:00 -08:00
|
|
|
import {ServerPlatformLocation} from './location';
|
2017-02-14 16:14:40 -08:00
|
|
|
import {PlatformState} from './platform_state';
|
2018-05-25 07:22:05 -07:00
|
|
|
import {ServerEventManagerPlugin} from './server_events';
|
2017-03-07 16:36:12 -08:00
|
|
|
import {ServerRendererFactory2} from './server_renderer';
|
2017-02-14 11:34:05 -08:00
|
|
|
import {ServerStylesHost} from './styles_host';
|
2017-02-14 19:48:48 -08:00
|
|
|
import {INITIAL_CONFIG, PlatformConfig} from './tokens';
|
2017-02-09 14:10:00 -08:00
|
|
|
|
2016-06-14 19:49:25 -07:00
|
|
|
function notSupported(feature: string): Error {
|
|
|
|
|
throw new Error(`platform-server does not support '${feature}'.`);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 12:33:29 -07:00
|
|
|
export const INTERNAL_SERVER_PLATFORM_PROVIDERS: StaticProvider[] = [
|
2017-02-14 16:14:40 -08:00
|
|
|
{provide: DOCUMENT, useFactory: _document, deps: [Injector]},
|
2017-02-22 16:49:46 -08:00
|
|
|
{provide: PLATFORM_ID, useValue: PLATFORM_SERVER_ID},
|
2017-09-09 15:12:13 -07:00
|
|
|
{provide: PLATFORM_INITIALIZER, useFactory: initDominoAdapter, multi: true, deps: [Injector]}, {
|
2017-08-03 12:33:29 -07:00
|
|
|
provide: PlatformLocation,
|
|
|
|
|
useClass: ServerPlatformLocation,
|
|
|
|
|
deps: [DOCUMENT, [Optional, INITIAL_CONFIG]]
|
|
|
|
|
},
|
|
|
|
|
{provide: PlatformState, deps: [DOCUMENT]},
|
2017-02-12 09:16:23 -08:00
|
|
|
// Add special provider that allows multiple instances of platformServer* to be created.
|
|
|
|
|
{provide: ALLOW_MULTIPLE_PLATFORMS, useValue: true}
|
2016-07-08 10:47:17 -07:00
|
|
|
];
|
|
|
|
|
|
2017-09-09 15:12:13 -07:00
|
|
|
function initDominoAdapter(injector: Injector) {
|
2020-04-13 16:40:21 -07:00
|
|
|
return () => {
|
|
|
|
|
DominoAdapter.makeCurrent();
|
|
|
|
|
};
|
2016-06-14 19:49:25 -07:00
|
|
|
}
|
|
|
|
|
|
2017-03-13 17:31:03 -07:00
|
|
|
export function instantiateServerRendererFactory(
|
|
|
|
|
renderer: RendererFactory2, engine: ɵAnimationEngine, zone: NgZone) {
|
|
|
|
|
return new ɵAnimationRendererFactory(renderer, engine, zone);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 16:59:24 -07:00
|
|
|
export const SERVER_RENDER_PROVIDERS: Provider[] = [
|
2017-03-07 16:36:12 -08:00
|
|
|
ServerRendererFactory2,
|
2017-03-13 17:31:03 -07:00
|
|
|
{
|
|
|
|
|
provide: RendererFactory2,
|
|
|
|
|
useFactory: instantiateServerRendererFactory,
|
|
|
|
|
deps: [ServerRendererFactory2, ɵAnimationEngine, NgZone]
|
|
|
|
|
},
|
2017-02-14 11:34:05 -08:00
|
|
|
ServerStylesHost,
|
|
|
|
|
{provide: SharedStylesHost, useExisting: ServerStylesHost},
|
2018-05-25 07:22:05 -07:00
|
|
|
{provide: EVENT_MANAGER_PLUGINS, multi: true, useClass: ServerEventManagerPlugin},
|
2016-11-02 16:59:24 -07:00
|
|
|
];
|
|
|
|
|
|
2016-06-14 19:49:25 -07:00
|
|
|
/**
|
2016-08-15 13:44:01 -07:00
|
|
|
* The ng module for the server.
|
|
|
|
|
*
|
2018-10-19 12:12:20 +01:00
|
|
|
* @publicApi
|
2016-06-14 19:49:25 -07:00
|
|
|
*/
|
2017-02-14 16:14:40 -08:00
|
|
|
@NgModule({
|
|
|
|
|
exports: [BrowserModule],
|
2019-03-19 19:41:12 -05:00
|
|
|
imports: [HttpClientModule, NoopAnimationsModule],
|
2017-03-01 11:16:56 -08:00
|
|
|
providers: [
|
|
|
|
|
SERVER_RENDER_PROVIDERS,
|
|
|
|
|
SERVER_HTTP_PROVIDERS,
|
|
|
|
|
{provide: Testability, useValue: null},
|
2018-05-17 07:33:50 -04:00
|
|
|
{provide: ViewportScroller, useClass: NullViewportScroller},
|
2017-03-01 11:16:56 -08:00
|
|
|
],
|
2017-02-14 16:14:40 -08:00
|
|
|
})
|
2016-08-15 13:44:01 -07:00
|
|
|
export class ServerModule {
|
|
|
|
|
}
|
2016-07-26 05:21:19 -07:00
|
|
|
|
2017-02-14 16:14:40 -08:00
|
|
|
function _document(injector: Injector) {
|
|
|
|
|
let config: PlatformConfig|null = injector.get(INITIAL_CONFIG, null);
|
2019-11-09 19:00:53 +00:00
|
|
|
const document = config && config.document ? parseDocument(config.document, config.url) :
|
|
|
|
|
getDOM().createHtmlDocument();
|
|
|
|
|
// Tell ivy about the global document
|
|
|
|
|
ɵsetDocument(document);
|
|
|
|
|
return document;
|
2017-02-14 16:14:40 -08:00
|
|
|
}
|
|
|
|
|
|
2016-07-26 05:21:19 -07:00
|
|
|
/**
|
2018-10-19 12:12:20 +01:00
|
|
|
* @publicApi
|
2016-07-26 05:21:19 -07:00
|
|
|
*/
|
2020-04-13 16:40:21 -07:00
|
|
|
export const platformServer: (extraProviders?: StaticProvider[]|undefined) => PlatformRef =
|
2016-08-15 13:44:01 -07:00
|
|
|
createPlatformFactory(platformCore, 'server', INTERNAL_SERVER_PLATFORM_PROVIDERS);
|
2016-07-08 10:47:17 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The server platform that supports the runtime compiler.
|
|
|
|
|
*
|
2018-10-19 12:12:20 +01:00
|
|
|
* @publicApi
|
2016-07-08 10:47:17 -07:00
|
|
|
*/
|
2016-07-26 05:21:19 -07:00
|
|
|
export const platformDynamicServer =
|
2016-08-15 19:37:42 -07:00
|
|
|
createPlatformFactory(platformCoreDynamic, 'serverDynamic', INTERNAL_SERVER_PLATFORM_PROVIDERS);
|