-
Notifications
You must be signed in to change notification settings - Fork 2
/
example-usage-server.js
50 lines (45 loc) · 1.07 KB
/
example-usage-server.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import path from 'path';
import http from 'http';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import HTMLDocument from './src/index';
const PORT = 8080;
function render(req, res) {
const props = {
scripts: [
{
src: '/dist/my-script.js',
},
{
file: path.join(__dirname, './test/test-script.js')
},
{
inline: 'var x = 2;'
}
],
stylesheets: [
{
href: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'
},
{
inline: 'p { font-size: large; }'
},
{
file: path.join(__dirname, './test/test-css.css')
}
],
universalState: {
foo: true
},
};
const documentEl = (
<HTMLDocument
{...props}>
<h1>Hello World</h1>
</HTMLDocument>
);
const markup = ReactDOMServer.renderToStaticMarkup(documentEl);
res.end(`<!DOCTYPE html>${markup}`);
}
const server = http.createServer(render);
server.listen(PORT, () => console.log(`ReactHTMLDocument dev server running on port ${PORT}`));