Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hagevvashi/305dd6c2f8c84ece51da238f6ded43bb to your computer and use it in GitHub Desktop.
Save hagevvashi/305dd6c2f8c84ece51da238f6ded43bb to your computer and use it in GitHub Desktop.
Node.jsでserver実装。htmlTemplateメソッド用意
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