Skip to content

Commit 1eab27c

Browse files
committed
prerender updated - headless chrome
1 parent 8b8ba11 commit 1eab27c

10 files changed

+516
-774
lines changed

.dockerignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Exclude all...
2+
*
3+
# ...but
4+
!lib
5+
!server.js
6+
!package.json

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
.vscode

.jshintrc

-46
This file was deleted.

Dockerfile

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
FROM node:latest
1+
FROM node:carbon
22

3-
MAINTAINER Pablo Ballester
3+
RUN apt-get update && apt-get install -y \
4+
apt-transport-https \
5+
ca-certificates \
6+
curl \
7+
gnupg \
8+
--no-install-recommends \
9+
&& curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
10+
&& echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
11+
&& apt-get update && apt-get install -y \
12+
google-chrome-stable \
13+
--no-install-recommends \
14+
&& rm -rf /var/lib/apt/lists/*
415

5-
RUN echo deb http://ftp.debian.org/debian/ jessie main contrib non-free > /etc/apt/source.list
16+
RUN mkdir -p /usr/src/app
17+
WORKDIR /usr/src/app
618

7-
RUN apt-get update -y && apt-get install -y \
8-
python2.7 python-pip \
9-
libfreetype6 libfontconfig
19+
COPY package.json /usr/src/app/
20+
RUN npm install
1021

11-
RUN mkdir /data
22+
COPY . /usr/src/app
1223

13-
ADD ./package.json /data/package.json
14-
RUN cd /data && npm install
15-
16-
ADD . /data/
17-
18-
CMD node /data/server.js
24+
CMD [ "npm", "start" ]

lib/redisCache.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ var cleanUrl = function(url) {
8383
};
8484

8585
module.exports = {
86-
beforePhantomRequest: function(req, res, next) {
86+
requestReceived: function(req, res, next) {
8787
if (req.method !== 'GET' || redisOnline !== true) {
8888
return next();
8989
}
@@ -99,14 +99,14 @@ module.exports = {
9999
});
100100
},
101101

102-
afterPhantomRequest: function(req, res, next) {
102+
pageLoaded: function(req, res, next) {
103103
if (redisOnline !== true) {
104104
return next();
105105
}
106106
// Don't cache anything that didn't result in a 200. This is to stop caching of 3xx/4xx/5xx status codes
107107
if (req.prerender.statusCode === 200) {
108108
var prerenderUrl = cleanUrl(req.prerender.url);
109-
client.set(prerenderUrl, req.prerender.documentHTML, function(err, reply) {
109+
client.set(prerenderUrl, req.prerender.content, function(err, reply) {
110110
// If library set to cache set an expiry on the key.
111111
if (!err && reply && ttl && ttl !== 0) {
112112
client.expire(prerenderUrl, ttl, function(err, didSetExpiry) {

lib/viewPort.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@ var width = 1024; // 1440;
44
var height = 1024; // 718;
55

66
module.exports = {
7-
onPhantomPageCreate: function (phantom, req, res, next) {
8-
req.prerender.page.run(width, height, function (width, height, resolve) {
9-
this.viewportSize = {
10-
width: width,
11-
height: height
12-
};
13-
resolve();
14-
}).then(function () {
15-
next();
16-
}).catch(function (err) {
17-
console.log('custom viewport size error', err);
18-
});
7+
requestReceived: function (req, res, next) {
8+
req.prerender.width = width,
9+
req.prerender.height = height
10+
next();
1911
}
2012
};

0 commit comments

Comments
 (0)