import * as React from "react" ; import RootComponent from "./component/RootComponent" ; import RootComponentRegistry from "./RootComponentRegistry" ; import { AemContext } from "./AemContext" ; import Cache from "./store/Cache" ; import * as ReactDom from "react-dom/server" ; import { Container } from "./di/Container" ; export interface ServerResponse { html : string ; state : string ; } export default class ServerRenderer { private registry : RootComponentRegistry ; private container : Container ; constructor ( registry , container ) { this . registry = registry ; this . container = container ; } public renderReactComponent ( path , resourceType , wcmmode , renderRootDialog ? ) { console . log ( "render react on path " + path ) ; console . log ( "render react component " + resourceType ) ; let comp = this . registry . getComponent ( resourceType ) ; if ( ! comp ) { throw new Error ( "cannot find component for resourceType " + resourceType ) ; } let ctx = { registry : this . registry , container : this . container } ; console . log ( "render root dialog " + renderRootDialog ) ; let html = ReactDom . renderToString ( < RootComponent aemContext = { ctx } comp = { comp } path = { path } wcmmode = { wcmmode } renderRootDialog = { ! ! renderRootDialog } />); let cache = this . container . get ( "cache" ) ; return { html : html , state : JSON . stringify ( cache . getFullState ( ) ) } ; } }