javascript - Not able to resolve webpage links when request goes through phantom js server -
i have installed phantom js server seo request crawler first passes through phantom js server , can convert dynamic web page static web page served crawler. server installed , testing on localhost.the url placed in browser or request able reach phantom js phantom js unable resolved web pages script links. stuck here.any great appreciated..here code
<code> 1. **angular-seo-server.js** var system = require('system'); if (system.args.length < 3) { console.log("missing arguments."); phantom.exit(); } var server = require('webserver').create(); var port = parseint(system.args[1]); var urlprefix = system.args[2]; var parse_qs = function(s) { var querystring = {}; var = document.createelement("a"); a.href = s; a.search.replace( new regexp("([^?=&]+)(=([^&]*))?", "g"), function($0, $1, $2, $3) { querystring[$1] = $3; } ); return querystring; }; 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.oninitialized = function() { page.evaluate(function() { settimeout(function() { window.callphantom(); }, 10000); }); }; page.open(url); }; server.listen(port, function (request, response) { var route = parse_qs(request.url)._escaped_fragment_; var url = urlprefix + request.url.slice(1, request.url.indexof('?')) + '#!' + decodeuricomponent(route); renderhtml(url, function(html) { response.statuscode = 200; response.write(html); response.close(); }); }); console.log('listening on ' + port + '...'); console.log('press ctrl+c stop.'); 2. **angular seo.js** angular.module('mybookingapp', [ 'ngcookies', 'ngresource', 'ngsanitize', 'ngroute', 'seo' ]) .config(function ($routeprovider) { $routeprovider .when('/', { templateurl: 'views/menu.jsp', controller: 'mainctrl' }) .when('/about', { templateurl: 'views/listing-page.jsp', controller: 'mainctrl' }) .otherwise({ redirectto: '/' }); }); !function(window, document, undefined) { var getmodule = function(angular) { return angular.module('seo', []) .run([ '$rootscope', function($rootscope) { $rootscope.htmlready = function() { $rootscope.$evalasync(function() { // fire after $digest settimeout(function() { // fire after dom rendering if (typeof window.callphantom == 'function') { window.callphantom(); } }, 0); }); }; } ]); }; if (typeof define == 'function' && define.amd) define(['angular'], getmodule); else getmodule(angular); }(window, document); 3. **app.js** angular.module('mybookingapp', [ 'ngcookies', 'ngresource', 'ngsanitize', 'ngroute', 'seo' ]) .config(function ($routeprovider,$locationprovider) { $locationprovider.hashprefix('!'); $locationprovider.html5mode(false); $routeprovider .when('/', { templateurl: 'views/menu.jsp', controller: 'mainctrl' }) .when('/about', { templateurl: 'views/listing-page.jsp', controller: 'mainctrl' }) .otherwise({ redirectto: '/' }); }); 4. **main.js** 'use strict'; angular.module('mybookingapp') .controller('mainctrl', function ($scope) { $scope.awesomethings = [ 'html5 boilerplate', 'angularjs', 'karma' ]; // seo requirement: // phantomjs pre-rendering workflow requires page declare, through htmlready(), // finished controller. $scope.htmlready(); }); 5. **jsp page scripts** <!doctype html> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <html lang="en-us" data-ng-app="mybookingapp"> <head> <meta name="fragment" content="!"> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- <script src="scripts/app.js"></script> --> <!-- <script src="scripts/controllers/main.js"></script> --> <!-- <script src="angular-seo.js"></script> --> <script src="<c:url value="/resources/js/angular/angular.min.js" />"></script> <script src="<c:url value="/resources/js/lawsonry/app/angular-seo.js" />"></script> <script src="<c:url value="/resources/js/lawsonry/app/controllers/main.js" />"></script> 6. error output http://127.0.0.1:8080/carservice/resources/js/angular/angular.min.j#!undefined http://127.0.0.1:8080/carservice/resources/js/angular/angular-seo.j#!undefined [enter image description here][1] </code> [1]: https://i.stack.imgur.com/3nctr.png
Comments
Post a Comment