Running web application & prerender node server on same machine

While using prerender server for making javascript heavy sites crawlable / google searchable we can map our site url to localhost:port as prerender may not work with exact urls.For setting up prerender server follow the instructions at :
http://mohiplanet.blogspot.com/2014/07/installconfigure-and-run-html-pre.html

Have a look at util.js :
https://github.com/prerender/prerender/blob/master/lib/util.js
on line 32 - line 35.You will see something like this:
  1. var newUrl = url.format(parts);
  2. if(newUrl[0] === '/') newUrl = newUrl.substr(1);
  3. return newUrl;
  4. };
Add your mapping url code there.
Something like:
  1. var newUrl = url.format(parts);
  2. if(newUrl[0] === '/') newUrl = newUrl.substr(1);
  3. newUrl=mapurl(newUrl);
  4. return newUrl;
  5. };

map url function:
  1. function mapurl(turl){
  2. var url=turl;
  3. if(url.indexOf('www.mysite.com') > -1){
  4. url=url.replace('www.mysite.com','localhost:8080');
  5. return url+'';
  6. }
  7. if(url.indexOf('mysite.com') > -1){
  8. url=url.replace('mysite.com','localhost:8080');
  9. return url+'';
  10. }
  11. return url+'';
  12. }


This will work if our app is hosted locally at http://localhost:8080/ and locally setup prerender port is 3000

No comments:

Post a Comment