in modules/express-engine/src/main.ts [33:68]
export function ngExpressEngine(setupOptions: Readonly<NgSetupOptions>) {
const engine = new CommonEngine(setupOptions.bootstrap, setupOptions.providers);
return function (
filePath: string,
options: object,
callback: (err?: Error | null, html?: string) => void,
) {
try {
const renderOptions = { ...options } as RenderOptions;
if (!setupOptions.bootstrap && !renderOptions.bootstrap) {
throw new Error('You must pass in a NgModule to be bootstrapped');
}
const req = renderOptions.req;
const res = renderOptions.res || req.res;
renderOptions.url =
renderOptions.url || `${req.protocol}://${req.get('host') || ''}${req.originalUrl}`;
renderOptions.documentFilePath = renderOptions.documentFilePath || filePath;
renderOptions.providers = [...(renderOptions.providers || []), getReqResProviders(req, res)];
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
(renderOptions.publicPath =
renderOptions.publicPath ?? setupOptions.publicPath ?? (options as any).settings?.views),
(renderOptions.inlineCriticalCss =
renderOptions.inlineCriticalCss ?? setupOptions.inlineCriticalCss);
engine
.render(renderOptions)
.then((html) => callback(null, html))
.catch(callback);
} catch (err) {
callback(err);
}
};
}