spee.ch/server/render/renderFullPage.js

41 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-12-17 05:28:35 +01:00
const md5File = require('md5-file');
const path = require('path');
const bundlePath = path.resolve('./public/bundle/bundle.js');
const bundleHash = md5File.sync(bundlePath);
2019-03-16 20:20:21 +01:00
const shortBundleHash = bundleHash.substring(0, 4);
2018-12-17 05:28:35 +01:00
module.exports = (helmet, html, preloadedState) => {
// take the html and preloadedState and return the full page
return `
<!DOCTYPE html>
<html lang="en" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
2019-03-16 20:20:21 +01:00
<meta name="google-site-verification" content="U3240KfVplLZSRCcOHxGuDFQO6eVUXKeFsSD2WJvdLo" />
<!--helmet-->
${helmet.title.toString()}
2018-02-23 08:36:37 +01:00
${helmet.meta.toString()}
${helmet.link.toString()}
<!--style sheets-->
2018-05-31 03:07:24 +02:00
<link rel="stylesheet" href="/bundle/style.css" type="text/css">
<!--google font-->
<link href="https://fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lora" rel="stylesheet">
</head>
2018-06-03 05:58:54 +02:00
<body>
<div id="react-app">${html}</div>
<script>
2019-03-16 20:20:21 +01:00
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(
/</g,
'\\\u003c'
)}
</script>
2018-12-17 05:28:35 +01:00
<script src="/bundle/bundle.js?${shortBundleHash}"></script>
</body>
</html>
`;
};