rasengan
Version:
The modern React Framework
31 lines (30 loc) • 1.3 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { loadModuleSSR } from '../../core/config/utils/load-modules.js';
import { TemplateLayout } from './index.js';
import { join, posix } from 'path/posix';
import { renderToStream } from '../../server/node/rendering.js';
/**
* Render the app to a stream
* @param StaticRouterComponent
* @param helmetContext
* @param res
* @returns
*/
export const render = async (StaticRouterComponent, res, options) => {
const { metadata, assets, buildOptions } = options;
// Root path
const rootPath = process.cwd();
let App;
let Template;
if (buildOptions) {
App = (await loadModuleSSR(posix.join(buildOptions.buildDirectory, buildOptions.serverPathDirectory, 'main.js'))).default;
Template = (await loadModuleSSR(join(buildOptions.buildDirectory, buildOptions.serverPathDirectory, 'template.js'))).default;
}
else {
// Import Main App Component
App = (await loadModuleSSR(`${rootPath}/src/main`)).default;
// Import Template
Template = (await loadModuleSSR(`${rootPath}/src/template`)).default;
}
await renderToStream(_jsx(TemplateLayout, { StaticRouterComponent: StaticRouterComponent, metadata: metadata, assets: assets, App: App, Template: Template }), res);
};