import importFresh from 'import-fresh' ; import path from 'path' ; import { AppInvocationInfoResolver , JsonObject } from './ssrMiddleware' ; param { string } baseAppPath returns { AppInvocationInfoResolver } export function getDefaultAppInvocationInfoResolver ( { appPathResolver = ( requestJson ) => { return path . resolve ( baseAppPath , requestJson . id , serverBundleName ) ; } , baseAppPath = './dist' , serverBundleName = 'server.bundle' , } ) { const resolver = ( requestJson ) => { const modulePath = appPathResolver ( requestJson as JsonObject ) ; const resolvedModule = importFresh ( modulePath ) ; const resolvedRenderFunctionName = ( requestJson as JsonObject ) . functionName || 'renderView' ; const renderFunction = resolvedModule [ resolvedRenderFunctionName ] ; if ( ! renderFunction ) { throw new Error ( `The module "${ modulePath }" has no export named "${ resolvedRenderFunctionName }".
        Ensure that your server bundle is transpiled to CommonJS (or equivalent) format that can be
        resolved by a Node.js 'require' statement. And ensure that your server bundle exports a function
        named "${ resolvedRenderFunctionName }".` ) ; } const renderFunctionArgs = ( requestJson as JsonObject ) . args ; return { renderFunction : ( ... args ) => { console . log ( `[SSR] rendering app at ${ modulePath } via render function named ${ resolvedRenderFunctionName }` ) ; return renderFunction ( ... args ) ; } , renderFunctionArgs , } ; } ; return resolver ; }