add renderer helper
This commit is contained in:
parent
510f1c81dd
commit
db8e8bfd61
18
src/helpers/renderer.js
Normal file
18
src/helpers/renderer.js
Normal file
@ -0,0 +1,18 @@
|
||||
import React from "react";
|
||||
import { renderToString } from "react-dom/server";
|
||||
import Home from "../client/components/Home";
|
||||
|
||||
export default () => {
|
||||
const content = renderToString(<Home />);
|
||||
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<div id="root">${content}</div>
|
||||
<script src="bundle.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
};
|
14
src/index.js
14
src/index.js
@ -1,24 +1,14 @@
|
||||
import express from 'express';
|
||||
import React from 'react';
|
||||
import { renderToString } from "react-dom/server";
|
||||
import renderer from './helpers/renderer';
|
||||
import Home from './client/components/Home'
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.static('public'));
|
||||
app.get('/', (req, res) => {
|
||||
const content = renderToString(<Home />);
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<div id="root">${content}</div>
|
||||
<script src="bundle.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
res.send(html);
|
||||
res.send(renderer());
|
||||
});
|
||||
|
||||
app.listen(3000, () => {
|
||||
|
Loading…
Reference in New Issue
Block a user