Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function renderAsync(req) {
// for material ui
global.navigator = global.navigator || {}
global.navigator.userAgent = req.headers['user-agent'] || 'all'
const fetcher = new ServerFetcher(
'http://localhost:3000/graphql',
{ headers: { cookie: req.headers.cookie } },
)
const { redirect, status, element } = await getFarceResult({
url: req.url,
historyMiddlewares,
routeConfig: Routes,
resolver: createResolver(fetcher),
render,
})
const locale = req.cookies && req.cookies.locale
const elementwithIntl = withIntl(element, locale)
const sheet = new ServerStyleSheet()
const app = ReactDOM.renderToString(sheet.collectStyles(elementwithIntl))
const relayPayload = serialize(fetcher, { isJSON: true })
const styleTags = sheet.getStyleTags()
const helmet = Helmet.renderStatic()
return {
async function serverSideRender(req, res, next) {
try {
const { redirect, status, element } = await getFarceResult({
url: req.url,
historyMiddlewares: [queryMiddleware],
routeConfig,
resolver,
render,
})
if (redirect) {
res.redirect(302, redirect.url)
return
}
res.status(status).send(`
<title>Found Relay example</title>