This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.ts
55 lines (45 loc) · 1.37 KB
/
render.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { ChunkExtractor } from '@loadable/server'
import { resolve } from 'path'
import { createElement } from 'react'
import { renderToStringWithData } from 'react-apollo'
import { Helmet } from 'react-helmet'
import { createStore } from 'redux'
import { ServerStyleSheet } from 'styled-components'
import LambdaContainerCache from './cache'
import App from './components/App'
import HTML from './document'
import reducer from '../../app/reducer'
import routes from '../../app/routes'
import theme from '../../app/theme'
export default async ({ location }) => {
const { client, introspectionQueryResultData } = await LambdaContainerCache
const statsFile = process.env.IS_OFFLINE
? resolve('.webpack/service/loadable-stats.json')
: resolve('loadable-stats.json')
const store = createStore(reducer)
await client.resetStore() // the cache persists between lambda requests
const extractor = new ChunkExtractor({ entrypoints: [], statsFile })
const sheet = new ServerStyleSheet()
const content = await renderToStringWithData(
createElement(App, {
client,
extractor,
location,
routes,
sheet: sheet.instance,
store,
theme
})
)
const helmet = Helmet.renderStatic()
const state = client.extract()
return HTML({
content,
extractor,
introspectionQueryResultData,
helmet,
sheet,
state,
store
})
}