Last active
November 24, 2020 14:11
-
-
Save hagevvashi/305dd6c2f8c84ece51da238f6ded43bb to your computer and use it in GitHub Desktop.
Node.jsでserver実装。htmlTemplateメソッド用意
This file contains 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
function templateHtml( | |
title: string, | |
reactDom: string, | |
styles: string, | |
scripts: string | |
): string { | |
return ` | |
<!doctype html> | |
<html> | |
<head> | |
<title>${title}</title> | |
${styles} | |
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1"/> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
${reactDom} | |
<script> | |
// globalに計測のapiが露出している場合などに備えて適当に用意しておく | |
window.anAnalyticsApi = {}; | |
</script> | |
${scripts} | |
</body> | |
</html> | |
`; | |
} | |
// 省略 | |
res.write( | |
templateHtml( | |
"Hello", | |
'<div id="app"></div>', | |
"<style>ol,ul{list-style:none;}</style>", | |
'<script src="/bundle.js"></script>' | |
) | |
); | |
// 省略 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment