Skip to content

Commit c5fda9f

Browse files
committed
readme & update prerender client
1 parent 6a4bf64 commit c5fda9f

5 files changed

Lines changed: 37 additions & 28 deletions

File tree

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Use this java filter that prerenders a javascript-rendered page using an externa
3838
2. Check to make sure we aren't requesting a resource (js, css, etc...)
3939
3. (optional) Check to make sure the url is in the whitelist
4040
4. (optional) Check to make sure the url isn't in the blacklist
41-
2. Make a `GET` request to the [prerender service](https://github.com/collectiveip/prerender)(phantomjs server) for the page's prerendered HTML
41+
2. Make a `GET` request to the [prerender service](https://github.com/prerender/prerender)(phantomjs server) for the page's prerendered HTML
4242
3. Return that HTML to the crawler
4343

4444
## Customization
@@ -56,7 +56,7 @@ We usually set the original url in an http header which is added by the reverse
5656

5757
### Using your own prerender service
5858

59-
If you've deployed the prerender service on your own, set the `PRERENDER_SERVICE_URL` environment variable so that this package points there instead. Otherwise, it will default to the service already deployed at `http://prerender.herokuapp.com`
59+
If you've deployed the prerender service on your own, set the `PRERENDER_SERVICE_URL` environment variable so that this package points there instead. Otherwise, it will default to the service already deployed at `http://service.prerender.io/`
6060

6161
$ export PRERENDER_SERVICE_URL=<new url>
6262

@@ -92,16 +92,21 @@ If you want to cache the caching, analytics, log or others, you can config it. I
9292

9393
## Testing
9494

95-
If you want to make sure your pages are rendering correctly:
95+
If your URLs use a hash-bang:
9696

97-
1. Open the Developer Tools in Chrome (Cmd + Atl + J)
98-
2. Click the Settings gear in the bottom right corner.
99-
3. Click "Overrides" on the left side of the settings panel.
100-
4. Check the "User Agent" checkbox.
101-
6. Choose "Other..." from the User Agent dropdown.
102-
7. Type `googlebot` into the input box.
103-
8. Refresh the page (make sure to keep the developer tools open).
97+
If you want to see `http://localhost:3000/#!/profiles/1234`
98+
Then go to `http://localhost:3000/?_escaped_fragment_=/profiles/1234`
10499

100+
If your URLs use push-state:
101+
102+
If you want to see `http://localhost:3000/profiles/1234`
103+
Then go to `http://localhost:3000/profiles/1234?_escaped_fragment_=`
104+
105+
106+
project demo test url:
107+
108+
http://localhost:8080/test/?_escaped_fragment_=
109+
105110
## License
106111

107112
The MIT License (MIT)

demo/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<artifactId>prerender-java</artifactId>
1414
<version>1.6.2</version>
1515
</dependency>
16-
<dependency>
17-
<groupId>com.github.greengerong</groupId>
18-
<artifactId>prerender-java-redis</artifactId>
19-
<version>0.0.1-SNAPSHOT</version>
20-
</dependency>
16+
<!--<dependency>-->
17+
<!--<groupId>com.github.greengerong</groupId>-->
18+
<!--<artifactId>prerender-java-redis</artifactId>-->
19+
<!--<version>0.0.1-SNAPSHOT</version>-->
20+
<!--</dependency>-->
2121
<dependency>
2222
<groupId>commons-io</groupId>
2323
<artifactId>commons-io</artifactId>

demo/src/main/webapp/WEB-INF/web.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
<param-name>crawlerUserAgents</param-name>
1616
<param-value>YahooSeeker</param-value>
1717
</init-param>
18-
<init-param>
19-
<param-name>preRenderEventHandler</param-name>
20-
<param-value>com.github.greengerong.PrerenderRedisCache</param-value>
21-
</init-param>
18+
<!--<init-param>-->
19+
<!--<param-name>preRenderEventHandler</param-name>-->
20+
<!--<param-value>com.github.greengerong.PrerenderRedisCache</param-value>-->
21+
<!--</init-param>-->
2222
</filter>
2323
<filter-mapping>
2424
<filter-name>prerender</filter-name>

prerender-java.iml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@
2323
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.6" level="project" />
2424
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.5" level="project" />
2525
</component>
26-
</module>
27-
26+
</module>

src/main/java/com/github/greengerong/PrerenderConfig.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
import com.google.common.collect.Lists;
5-
import org.apache.commons.lang.StringUtils;
65
import org.apache.http.HttpHost;
76
import org.apache.http.client.config.RequestConfig;
87
import org.apache.http.impl.client.CloseableHttpClient;
@@ -84,7 +83,8 @@ public String getForwardedURLHeader() {
8483
public List<String> getCrawlerUserAgents() {
8584
List<String> crawlerUserAgents = Lists.newArrayList("baiduspider",
8685
"facebookexternalhit", "twitterbot", "rogerbot", "linkedinbot", "embedly", "quora link preview"
87-
, "showyoubo", "outbrain", "pinterest", "developers.google.com/+/web/snippet", "slackbot");
86+
, "showyoubo", "outbrain", "pinterest", "developers.google.com/+/web/snippet", "slackbot", "vkShare",
87+
"W3C_Validator", "redditbot", "Applebot");
8888
final String crawlerUserAgentsFromConfig = config.get("crawlerUserAgents");
8989
if (isNotBlank(crawlerUserAgentsFromConfig)) {
9090
crawlerUserAgents.addAll(Arrays.asList(crawlerUserAgentsFromConfig.trim().split(",")));
@@ -94,10 +94,10 @@ public List<String> getCrawlerUserAgents() {
9494
}
9595

9696
public List<String> getExtensionsToIgnore() {
97-
List<String> extensionsToIgnore = Lists.newArrayList(".xml", ".js", ".css", ".less", ".png", ".jpg", ".jpeg",
98-
".gif", ".pdf", ".doc", ".txt", ".zip", ".mp3", ".rar", ".exe", ".wmv", ".doc", ".avi", ".ppt", ".mpg",
99-
".mpeg", ".tif", ".wav", ".mov", ".psd", ".ai", ".xls", ".mp4", ".m4a", ".swf", ".dat", ".dmg",
100-
".iso", ".flv", ".m4v", ".torrent");
97+
List<String> extensionsToIgnore = Lists.newArrayList(".js", ".json", ".css", ".xml", ".less", ".png", ".jpg",
98+
".jpeg", ".gif", ".pdf", ".doc", ".txt", ".ico", ".rss", ".zip", ".mp3", ".rar", ".exe", ".wmv",
99+
".doc", ".avi", ".ppt", ".mpg", ".mpeg", ".tif", ".wav", ".mov", ".psd", ".ai", ".xls", ".mp4",
100+
".m4a", ".swf", ".dat", ".dmg", ".iso", ".flv", ".m4v", ".torrent", ".woff", ".ttf");
101101
final String extensionsToIgnoreFromConfig = config.get("extensionsToIgnore");
102102
if (isNotBlank(extensionsToIgnoreFromConfig)) {
103103
extensionsToIgnore.addAll(Arrays.asList(extensionsToIgnoreFromConfig.trim().split(",")));
@@ -124,6 +124,11 @@ public List<String> getBlacklist() {
124124

125125
public String getPrerenderServiceUrl() {
126126
final String prerenderServiceUrl = config.get("prerenderServiceUrl");
127-
return isNotBlank(prerenderServiceUrl) ? prerenderServiceUrl : PRERENDER_IO_SERVICE_URL;
127+
return isNotBlank(prerenderServiceUrl) ? prerenderServiceUrl : getDefaultPrerenderIoServiceUrl();
128+
}
129+
130+
private String getDefaultPrerenderIoServiceUrl() {
131+
final String prerenderServiceUrlInEnv = System.getProperty("PRERENDER_SERVICE_URL");
132+
return isNotBlank(prerenderServiceUrlInEnv) ? prerenderServiceUrlInEnv : PRERENDER_IO_SERVICE_URL;
128133
}
129134
}

0 commit comments

Comments
 (0)