UNPKG

5.7 kBSource Map (JSON)View Raw
1{"version":3,"file":"express-engine.mjs","sources":["../../../../../../modules/express-engine/src/main.ts","../../../../../../modules/express-engine/public_api.ts","../../../../../../modules/express-engine/index.ts","../../../../../../modules/express-engine/express-engine.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport type { StaticProvider } from '@angular/core';\nimport { CommonEngine, RenderOptions as CommonRenderOptions } from '@nguniversal/common/engine';\nimport { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens';\nimport type { Request, Response } from 'express';\n\n/**\n * These are the allowed options for the engine\n */\nexport type NgSetupOptions = Pick<\n CommonRenderOptions,\n 'bootstrap' | 'providers' | 'publicPath' | 'inlineCriticalCss'\n>;\n\n/**\n * These are the allowed options for the render\n */\nexport interface RenderOptions extends CommonRenderOptions {\n req: Request;\n res?: Response;\n}\n\n/**\n * This is an express engine for handling Angular Applications\n */\nexport function ngExpressEngine(setupOptions: Readonly<NgSetupOptions>) {\n const engine = new CommonEngine(setupOptions.bootstrap, setupOptions.providers);\n\n return function (\n filePath: string,\n options: object,\n callback: (err?: Error | null, html?: string) => void,\n ) {\n try {\n const renderOptions = { ...options } as RenderOptions;\n if (!setupOptions.bootstrap && !renderOptions.bootstrap) {\n throw new Error('You must pass in a NgModule to be bootstrapped');\n }\n\n const { req } = renderOptions;\n const res = renderOptions.res ?? req.res;\n\n renderOptions.url =\n renderOptions.url ?? `${req.protocol}://${req.get('host') || ''}${req.baseUrl}${req.url}`;\n renderOptions.documentFilePath = renderOptions.documentFilePath ?? filePath;\n renderOptions.providers = [...(renderOptions.providers ?? []), getReqResProviders(req, res)];\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n renderOptions.publicPath =\n renderOptions.publicPath ?? setupOptions.publicPath ?? (options as any).settings?.views;\n renderOptions.inlineCriticalCss =\n renderOptions.inlineCriticalCss ?? setupOptions.inlineCriticalCss;\n\n engine\n .render(renderOptions)\n .then((html) => callback(null, html))\n .catch(callback);\n } catch (err) {\n callback(err);\n }\n };\n}\n\n/**\n * Get providers of the request and response\n */\nfunction getReqResProviders(req: Request, res?: Response): StaticProvider[] {\n const providers: StaticProvider[] = [\n {\n provide: REQUEST,\n useValue: req,\n },\n ];\n if (res) {\n providers.push({\n provide: RESPONSE,\n useValue: res,\n });\n }\n\n return providers;\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport { ngExpressEngine, NgSetupOptions, RenderOptions } from './src/main';\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport * from './public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAAA;;;;;;AAMG;AAuBH;;AAEG;AACG,SAAU,eAAe,CAAC,YAAsC,EAAA;AACpE,IAAA,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;AAEhF,IAAA,OAAO,UACL,QAAgB,EAChB,OAAe,EACf,QAAqD,EAAA;;QAErD,IAAI;AACF,YAAA,MAAM,aAAa,GAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAQ,OAAO,CAAmB,CAAC;YACtD,IAAI,CAAC,YAAY,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE;AACvD,gBAAA,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;AACnE,aAAA;AAED,YAAA,MAAM,EAAE,GAAG,EAAE,GAAG,aAAa,CAAC;YAC9B,MAAM,GAAG,GAAG,CAAA,EAAA,GAAA,aAAa,CAAC,GAAG,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAA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