You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import renderToString from 'preact-render-to-string'
|
|
// import { App } from './App'
|
|
import { ServerAsyncCallbacksContext, DatabaseContext, MetadataContext, ServerContext } from './hooks'
|
|
|
|
import { RenderedPage, ServerAsyncCallback } from '../shared/ssr'
|
|
import { App } from './App'
|
|
import { DatabaseConnection } from '../shared/database'
|
|
|
|
export default (url: string, db: DatabaseConnection): RenderedPage => {
|
|
const metadata = {}
|
|
const asyncCallbacks: ServerAsyncCallback[] = []
|
|
|
|
const html = renderToString(
|
|
<MetadataContext.Provider value={metadata}>
|
|
<ServerContext.Provider value={true}>
|
|
<DatabaseContext.Provider value={db}>
|
|
<ServerAsyncCallbacksContext.Provider value={asyncCallbacks}>
|
|
<App url={url} />
|
|
</ServerAsyncCallbacksContext.Provider>
|
|
</DatabaseContext.Provider>
|
|
</ServerContext.Provider>
|
|
</MetadataContext.Provider>
|
|
)
|
|
|
|
return { html, metadata, asyncCallbacks }
|
|
}
|