Skip to content

Commit 950bb8e

Browse files
committed
Add React
1 parent 46034f3 commit 950bb8e

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

server/api/server.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1+
import React from 'react'
2+
import { renderToString } from 'react-dom/server'
3+
4+
// import App from '../src/components/App'
5+
// ^ this would result in errors, so we make a small example App:
6+
const App = () => <b>My server-rendered React app</b>
7+
18
export default (req, res) => {
29
res.status(200).send(`
3-
<!doctype html>
4-
<html lang="en">
5-
6-
<head>
7-
<meta charset="utf-8">
8-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
9-
<title>The GraphQL Guide</title>
10-
</head>
11-
12-
<body>
13-
Server-side rendered: ${req.headers['user-agent']}
14-
</body>
15-
16-
</html>
17-
`)
10+
<!doctype html>
11+
<html lang="en">
12+
13+
<head>
14+
<meta charset="utf-8">
15+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
16+
<title>The GraphQL Guide</title>
17+
</head>
18+
19+
<body>
20+
<div id="root">
21+
${renderToString(<App />)}
22+
</div>
23+
</body>
24+
25+
</html>
26+
`)
1827
}

0 commit comments

Comments
 (0)