Created
February 18, 2020 19:53
-
-
Save dagda1/c2b5379256fd3e44fe1bb9903fd6e3e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export async function render({ req, res }: RendererOptions): Promise<void> { | |
const context: StaticRouterContext = {}; | |
const appString = renderToString( | |
<StaticRouter location={req.url} context={context}> | |
<Routes /> | |
</StaticRouter>, | |
); | |
const scriptTags = ['vendor', 'client'] | |
.filter(k => !!assets[k]?.js) | |
.map(k => `<script src="${assets[k].js}" defer crossorigin></script>`) | |
.join('\n'); | |
res.status(HttpStatusCode.Ok).send(` | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<meta httpEquiv="X-UA-Compatible" content="IE=edge" /> | |
<meta charSet="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
${`<link rel="stylesheet" href="${assets.client.css}">`} | |
</head> | |
<body> | |
<div id="root">${appString}</div> | |
${scriptTags} | |
</body> | |
</html> | |
`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment