import * as ReactDOMServer from 'react-dom/server' import cookie from 'cookie' import config from 'config' // import our main App component import App from '../../src/App' import { getLinks } from '../sape' import { StaticRouter } from 'react-router-dom/server' import { VisitorProvider } from '../../src/ui/VisitorContext' import path from 'path' import fs from 'fs' const STATIC_ROOT = config.get('service.static_root') || path.resolve(__dirname, 'public') const serverRenderer = async (req, res) => { // point to the html file created by CRA's build tool const filePath = path.resolve(STATIC_ROOT, 'index.html') // links const cookies = cookie.parse(req.headers.cookie || '') const links = await getLinks(req.originalUrl, cookies['sape_cookie']) fs.readFile(filePath, 'utf8', (err, htmlData) => { if (err) { console.error('err', err) return res.status(404).end() } const routerContext = {} const props = { footer: links.join(' ') } const marker = '