-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demos): enable SSR for FA-in-FA demo and fix externals config (#326
- Loading branch information
1 parent
803067e
commit 0f13102
Showing
5 changed files
with
82 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/demos/src/feature-app-in-feature-app/integrator.node.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {FeatureAppManager, FeatureServiceRegistry} from '@feature-hub/core'; | ||
import {loadCommonJsModule} from '@feature-hub/module-loader-commonjs'; | ||
import {FeatureAppLoader, FeatureHubContextProvider} from '@feature-hub/react'; | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom/server'; | ||
import {AppRendererOptions, AppRendererResult} from '../start-server'; | ||
|
||
export default async function renderApp({ | ||
port | ||
}: AppRendererOptions): Promise<AppRendererResult> { | ||
const featureAppNodeUrl = `http://localhost:${port}/feature-app.commonjs.js`; | ||
const featureServiceRegistry = new FeatureServiceRegistry(); | ||
|
||
const featureAppManager = new FeatureAppManager(featureServiceRegistry, { | ||
moduleLoader: loadCommonJsModule | ||
}); | ||
|
||
// In a real-world integrator, instead of preloading a Feature App manually | ||
// before rendering, the Async SSR Manager would be used to handle the | ||
// asynchronous server-side rendering (see "Server-Side Rendering" demo). | ||
await featureAppManager.preloadFeatureApp(featureAppNodeUrl); | ||
|
||
const html = ReactDOM.renderToString( | ||
<FeatureHubContextProvider value={{featureAppManager}}> | ||
<FeatureAppLoader | ||
src="feature-app.umd.js" | ||
serverSrc={featureAppNodeUrl} | ||
/> | ||
</FeatureHubContextProvider> | ||
); | ||
|
||
return {html}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters