-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (26 loc) · 739 Bytes
/
server.js
File metadata and controls
32 lines (26 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const express = require("express");
const { renderToString } = require("react-dom/server");
const SSR = require("./static");
server(parseInt(process.env.PORT, 10) || 8080);
function server(port) {
const app = express();
app.use(express.static("static"));
app.get("/", (req, res) =>
res.status(200).send(renderMarkup(renderToString(SSR)))
);
app.listen(port, () => process.send && process.send("online"));
}
function renderMarkup(html) {
return `<!DOCTYPE html>
<html>
<head>
<title>Webpack SSR Demo</title>
<meta charset="utf-8" />
</head>
<body>
<div id="app">${html}</div>
<script src="./index.js"></script>
<script src="${process.env.BROWSER_REFRESH_URL}"></script>
</body>
</html>`;
}