This project was bootstrapped with Create React App.
- Clone this repo.
git clone https://github.com/Dragon-Huang0403/react-express-ssr-tutorial.git
- Install dependency.
npm install
- To see server side render react with express server to be seen in localhost:3001
-
Observe files.
- webpack.server.js for bundling express app.
- src/common, react app files.
- src/server, express app.
-
Run
npm run all
, to start express server in localhost:3001. -
Display build/index.html in localhost:3001.
-
Use react-dom/server method, renderToString, to render App.js only.
-
Try to render whole html(build/index.html).
- Hint: try
fs.readFile(filePath, 'utf8', callback);
- Hint: try
-
Hydrate App.
-
Well done!!
In the project directory, you can run:
Runs the app in the client side.\
To run express server.\
To auto build react script.\