Skip to content

Commit

Permalink
use request header hostname instead of Meteor.absoluteUrl()
Browse files Browse the repository at this point in the history
This works with multitenant applications.
  • Loading branch information
petermikitsh committed Oct 29, 2015
1 parent 62aa2d6 commit 96b890b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
1 change: 1 addition & 0 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Package.describe({
name: 'wyvrn:spiderable',
summary: "Makes the application crawlable to web spiders",
version: "1.0.7"
});
Expand Down
18 changes: 6 additions & 12 deletions phantom_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ var page = require('webpage').create();

var isReady = function () {
return page.evaluate(function () {
if (typeof Meteor === 'undefined'
|| Meteor.status === undefined
|| !Meteor.status().connected) {
return false;
if (typeof Meteor !== 'undefined'
&& typeof(Meteor.status) !== 'undefined'
&& Meteor.status().connected) {
Deps.flush();
return DDP._allSubscriptionsReady();
}
if (typeof Package === 'undefined'
|| Package.spiderable === undefined
|| Package.spiderable.Spiderable === undefined
|| !Package.spiderable.Spiderable._initialSubscriptionsStarted) {
return false;
}
Tracker.flush();
return DDP._allSubscriptionsReady();
return false;
});
};

Expand Down
10 changes: 5 additions & 5 deletions spiderable_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Spiderable.userAgentRegExps = [
/^facebookexternalhit/i, /^linkedinbot/i, /^twitterbot/i];

// how long to let phantomjs run before we kill it
var REQUEST_TIMEOUT = 15*1000;
var REQUEST_TIMEOUT = 30*1000;
// maximum size of result HTML. node's default is 200k which is too
// small for our docs.
var MAX_BUFFER = 5*1024*1024; // 5MB
var MAX_BUFFER = 10*1024*1024; // 5MB

// Exported for tests.
Spiderable._urlForPhantom = function (siteAbsoluteUrl, requestUrl) {
Expand Down Expand Up @@ -59,7 +59,7 @@ WebApp.connectHandlers.use(function (req, res, next) {
_.any(Spiderable.userAgentRegExps, function (re) {
return re.test(req.headers['user-agent']); })) {

var url = Spiderable._urlForPhantom(Meteor.absoluteUrl(), req.url);
var url = Spiderable._urlForPhantom(req.headers['x-forwarded-proto'] + '://' + req.headers.host, req.url);

// This string is going to be put into a bash script, so it's important
// that 'url' (which comes from the network) can neither exploit phantomjs
Expand Down Expand Up @@ -108,7 +108,7 @@ WebApp.connectHandlers.use(function (req, res, next) {
("exec phantomjs " + phantomJsArgs + " /dev/stdin <<'END'\n" +
phantomScript + "END\n")],
{timeout: REQUEST_TIMEOUT, maxBuffer: MAX_BUFFER},
function (error, stdout, stderr) {
Meteor.bindEnvironment( function (error, stdout, stderr) {
if (!error && /<html/i.test(stdout)) {
res.writeHead(200, {'Content-Type': 'text/html; charset=UTF-8'});
res.end(stdout);
Expand All @@ -122,7 +122,7 @@ WebApp.connectHandlers.use(function (req, res, next) {

next();
}
});
}));
} else {
next();
}
Expand Down

0 comments on commit 96b890b

Please sign in to comment.