-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (28 loc) · 766 Bytes
/
server.js
File metadata and controls
32 lines (28 loc) · 766 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
import express from "express"
import React from "react"
import {renderToString} from "react-dom/server"
import Application from "./src/app"
const app = express()
app.get("/", (req, res) => {
const model = {
counter1: 10000,
counter2: -100000
}
res.send(`<!DOCTYPE html>
<html>
<head>
<title>2.x basic usage</title>
</head>
<body>
<div id="app">${renderToString(<Application {...model} />)}</div>
<script type="text/javascript">
window.INITIAL_MODEL = ${JSON.stringify(model)};
</script>
<script type="text/javascript" src="/static/bundle.js"></script>
</body>
</html>`)
})
app.get("/static/bundle.js", function(req, res) {
res.sendFile("bundle.js", {root: __dirname})
})
app.listen(3000)