UNPKG

@hapiness/ng-universal

Version:

This is a Hapiness Engine for running Angular Apps on the server for server side rendering.

163 lines (162 loc) 4.05 kB
import { Observable } from 'rxjs'; import { NgSetupOptions } from '../../interfaces'; import { HttpResponse, HttpServerRequest } from '@hapiness/core/httpserver'; import { HttpServerReply } from '../reply'; import { HttpUtils } from '../utils'; export declare class NgEngineService { private _config; private _request; private _reply; private _utils; /** * This holds a cached version of each data used. */ private _dataCache; /** * Map of Module Factories */ private _factoryCacheMap; /** * Angular compiler factory */ private _compilerFactory; /** * Angular compiler instance */ private _compiler; /** * Renders a {@link NgModuleFactory} to string. * * `document` is the full document HTML of the page to render, as a string. * `url` is the URL for the current render request. * `extraProviders` are the platform level providers for the current render request. * * store original function to stub it in tests */ private readonly _renderModuleFactory; /** * Helper function for getting the providers object for the MODULE_MAP * * @param {ModuleMap} moduleMap Map to use as a value for MODULE_MAP * * store original function to stub it in tests */ private readonly _provideModuleMap; /** * Store mimos instance to stub it in tests */ private _mimos; /** * Service constructor * * @param {NgSetupOptions} _config * @param {HttpServerRequest} _request * @param {HttpServerReply} _reply helper to modify the response * @param {HttpUtils} _utils helper to manage data in request/response like cookies */ constructor(_config: NgSetupOptions, _request: HttpServerRequest, _reply: HttpServerReply, _utils: HttpUtils); /** * Returns universal rendering of HTML * * @return {Observable<HttpResponse<any>>} */ universal(): Observable<HttpResponse<any>>; /** * Returns HttpResponse<any> from static content * * @param _ * * @returns {Observable<HttpResponse<any>>} * * @private */ private _getStaticContent; /** * Returns content from NgFactoryModule * * @param _ * * @returns {Observable<HttpResponse<any>>} * * @private */ private _getFactoryContent; /** * Function to check request parameter * * @returns {Observable<true>} * * @private */ private _checkRequest; /** * Function to check module config * * @returns {Observable<NgSetupOptions>} * * @private */ private _checkConfig; /** * Builds extra providers * * @param {StaticProvider[]} providers * @param {ModuleMap} lazyModuleMap * @param {string} filePath * * @return {Provider[]} * * @private */ private _extraProviders; /** * Get a factory from a bootstrapped module / module factory * * @param {Type<{}> | NgModuleFactory<{}>} moduleOrFactory * * @return {Observable<NgModuleFactory<{}>>} * * @private */ private _getFactory; /** * Compile the module and cache it * * @param {Type<{}>} module to compile and cache * * @return {Observable<NgModuleFactory<{}>>} * * @private */ private _compile; /** * Get providers of the request and response * * @return {StaticProvider[]} * * @private */ private _getAdditionalProviders; /** * Returns document path * * @param {StaticContent} staticContent * @param {string} mime * @param {string} staticFileUrl * * @returns {string} * * @private */ private _buildFilePath; /** * Returns document from cache or file system * * @param {string} filePath path to the file * * @return {Buffer} * * @private */ private _getDocument; }