Skip to content

Commit

Permalink
merged latest changes from steeve's repo, using window.callPhantom to…
Browse files Browse the repository at this point in the history
… invoke callback instead of firing an event
  • Loading branch information
meshaabi committed Dec 29, 2013
1 parent 8afc76d commit d0e6392
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
23 changes: 12 additions & 11 deletions angular-seo-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,37 @@ var renderHtml = function(url, cb) {
var page = require('webpage').create();
page.settings.loadImages = false;
page.settings.localToRemoteUrlAccessEnabled = true;

page.onCallback = function() {
cb(page.content);
page.close();
};
// page.onConsoleMessage = function(msg, lineNum, sourceId) {
// console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
// };

// page.onConsoleMessage = function(msg, lineNum, sourceId) {
// console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
// };

page.onInitialized = function() {
page.evaluate(function() {
document.addEventListener('__htmlReady__', function() {
window.callPhantom();
}, false);
setTimeout(function() {
window.callPhantom();
}, 10000);
});
};

page.open(url);
};

server.listen(port, function (request, response) {
var url = request.url;
var route = url.replace("?_escaped_fragment_=","#");

renderHtml('http://' + request.headers.Host + route, function(html) {
var urlPrefix = 'http://' + request.headers.Host;
var route = request.url.replace("?_escaped_fragment_=","#");
var url = urlPrefix + decodeURIComponent(route);
renderHtml(url , function(html) {
response.statusCode = 200;
response.write(html);
response.close();
});
});

console.log('Listening on ' + port + '...');
console.log('Press Ctrl+C to stop.');
console.log('Press Ctrl+C to stop.');
8 changes: 4 additions & 4 deletions angular-seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
$rootScope.htmlReady = function() {
$rootScope.$evalAsync(function() { // fire after $digest
setTimeout(function() { // fire after DOM rendering
var evt = document.createEvent('Event');
evt.initEvent('__htmlReady__', true, true);
document.dispatchEvent(evt);
if (typeof window.callPhantom == 'function') {
window.callPhantom();
}
}, 0);
});
};
Expand All @@ -20,4 +20,4 @@
define(['angular'], getModule);
else
getModule(angular);
}(window, document);
}(window, document);

0 comments on commit d0e6392

Please sign in to comment.