File tree Expand file tree Collapse file tree 1 file changed +24
-15
lines changed Expand file tree Collapse file tree 1 file changed +24
-15
lines changed Original file line number Diff line number Diff line change
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
+
1
8
export default ( req , res ) => {
2
9
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
+ ` )
18
27
}
You can’t perform that action at this time.
0 commit comments