我在Xampp上安装了prerender.io,我什么也没做。刚刚安装了所有预呈现者需求,并按照prerender.io和https://github.com/zf-fr/zfr-prerender上的文档进行操作。 所以我想说我已经把这里的预呈现放在了这里:
/public/assets/services/prerender
在控制台中我跑了:
npm install
node server.js
Zfr-prerender是中间件,我只改变了一个东西,即引用prerender的url:
'prerender_url' => 'http://localhost:3000/public/assets/services/prerender',
在我的浏览器中,我转到:
本地主机/商店/ api / list?_escaped_fragment _ =
当找不到路由时,angularJS的路由器重定向到/ list / 1:
ListerApp.config(['$routeProvider', '$httpProvider', '$locationProvider', function($routeProvider, $httpProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
$routeProvider
.when('/list/:page?',
{
templateUrl : '/assets/services/partials/list.html',
controller : 'ListerCtrl',
reloadOnSearch : false,
js : ['/assets/min/shoplist_js.min.js', '/assets/min/bootstrap-typeahead.min.js'],
//css : [],
resolve : {
sharedServiceAppData: function($sharedData){
// sharedFactoryAppData will also be injectable in your controller, if you don't want this you could create a new promise with the $q service
return $sharedData.promise();
//return;
}
}
}
)
.otherwise({ redirectTo: '/list/1' });
}]);
控制台正在告诉我:
getting public/assets/services/prerender/http://localhost/shop/api/list
got 200 in 419ms for public/assets/services/prerender/http://localhost/shop/api/list
但所有phantomJS返回的都是奇怪的字符。
public function prerenderPost(PrerenderEvent $event)
{
// This is the response we get from the Prerender service
$response = $event->getResponse();
var_dump($response->getHeaders());
var_dump($response->getContent());
// You could get the body and put it in cache
// ...
}
这些是标题,var_dump($ response-> getHeaders()):
array (size=5)
0 =>
array (size=2)
'name' => string 'Content-Type' (length=12)
'line' => string 'Content-Type: text/html;charset=UTF-8' (length=37)
1 =>
array (size=2)
'name' => string 'Content-Encoding' (length=16)
'line' => string 'Content-Encoding: gzip' (length=22)
2 =>
array (size=2)
'name' => string 'Content-Length' (length=14)
'line' => string 'Content-Length: 45' (length=18)
3 =>
array (size=2)
'name' => string 'Date' (length=4)
'line' => string 'Date: Thu, 30 Oct 2014 18:23:39 GMT' (length=35)
4 =>
array (size=2)
'name' => string 'Connection' (length=10)
'line' => string 'Connection: close'
这是一个PHP var_dump($ response-> getContent()):
string'<³³É(Éͱ³ÉHML±³Ñ‡PIù)•@“+ 'H' '(长度= 45)
<³É(Éͱ³ÉHML±³Ñ‡PIù)•@“+'H'
答案 0 :(得分:0)
首先,要解压缩并获取您需要的内容
$response->getBody()
其次,如果您有一台非常老旧的计算机,在de Zfr-prenderer模块中增加套接字超时可能会很有用。