Skip to content

Commit 4193c6c

Browse files
authored
Update README.md
1 parent 2f748d4 commit 4193c6c

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
## Prender Proxy - React Js App
1+
## React Server Side Rendering with Puppeteer if googlebot, yahoobot detected.
22
React JS Client > Cloudflare > Proxy Server (Pupeeter)
33

4+
This script is intend to render the react server side but using Pre-Rendering technique and it will prerender only if it detects the googlebot, yahoobot or bing.
5+
Before we used to have React SSR on server side but as our code grows the issues also started to grow which made me rethink to alternative strategy to render the APP server side as i needed the SSR only for SEO so google and other search engines can crawl my site and have good SEO ranking. So here's the solution.
6+
7+
#### Required Skills
8+
* You know how to configure Nginx
9+
* You have knowledge how to host node.js app using NGINX
10+
411
#### Few points to remeber
512
* Proxy will not work if you are trying to achieve this (You want requests to go from the browser via **Cloudflare’s proxy** to your **Nginx proxy** and then on to your **internal server**.)
613
* You need to disable the proxy cloud on cloudflare for your Proxy A Records for e.g. in my case it was A - prerender.lucian.com - 11.22.33.343 (Proxy Icon Disabled)
714

15+
#### Use Case
16+
* We have 2 servers SERVER A and SERVER B
17+
* SERVER A hosts the React JS app as plain HTML
18+
* SERVER B will be the proxy server
19+
820
## STEPS
9-
* Create a prerender.lucian.com.conf in nginx > sites-avaiable
21+
* Create a NGINX conf file /etc/nginx/sites-available/prerender.lucian.com.conf
1022
```
1123
server {
1224
listen 80;
@@ -24,9 +36,24 @@ React JS Client > Cloudflare > Proxy Server (Pupeeter)
2436
```
2537

2638
* Clone the node.js app and start node server.js
27-
So now your server will be listening on http://127.0.0.1:3001
28-
29-
* You can test the prerendering using http://prerender.lucian.com?url=https://www.google.com
39+
```
40+
git clone https://github.com/khanakia/reactjs-prerender.git
41+
cd reactjs-prerender
42+
yarn
43+
node server.js
44+
```
45+
Note: To debug you can use this command **env DEBUG="puppeteer:*" node script.js**
46+
47+
If you get **CHROME** related library missing etc. errors you can check these 2 links
48+
* https://blog.softhints.com/ubuntu-16-04-server-install-headless-google-chrome/
49+
https://github.com/GoogleChrome/puppeteer/issues/3443
50+
* https://blog.softhints.com/ubuntu-16-04-server-install-headless-google-chrome/
51+
https://github.com/GoogleChrome/puppeteer/issues/3443
52+
53+
Note: You can use forever or pm2 to run your script as background process
54+
55+
* So now your server will be listening on http://127.0.0.1:3001
56+
You can test the prerendering using http://prerender.lucian.com?url=https://www.google.com
3057

3158
* If everything works fine then login in to your React JS Server and modify the config file accordingly
3259

0 commit comments

Comments
 (0)