在localhost上为meteor.js设置prerender.io

时间:2016-11-24 17:48:35

标签: javascript node.js meteor web-crawler prerender

1)我已经安装并运行了应用程序meteor.js https://github.com/meteor/simple-todos-react

2)我已将prerender服务器安装在应用程序目录附近:

git clone https://github.com/prerender/prerender.git
cd prerender
npm install

并设置端口:

export PORT=3050

结束

node server.js

3)我已经安装了模块prerender-node

meteor npm install prerender-node --save

设置环境变量:

export PRERENDER_SERVICE_URL="http://localhost:3050/"

4)我在./server/main.js写道:

import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
import prerenderIO from 'prerender-node';

Meteor.startup(() => {
  prerenderIO.set('host', 'localhost');
  prerenderIO.set('protocol', 'http');
  prerenderIO.set('port', '3000');
  WebApp.connectHandlers.use(prerenderIO);
});

但是当我转到view-source:http://localhost:3000/?_escaped_fragment_=链接时,我看不到呈现的html

我看到一个错误:

GET http://localhost:3000/?_escaped_fragment_= 504 

我做错了什么?

2 个答案:

答案 0 :(得分:1)

import prerenderio from 'prerender-node';
Meteor.startup(() => {
const settings = Meteor.settings.PrerenderIO;
if (settings && settings.token && settings.protocol) {
    prerenderio.set('prerenderToken', settings.token);
    prerenderio.set('protocol', settings.protocol);
    prerenderio.set('forwardHeaders', true);
    prerenderio.set('afterRender', function afterRender(error) {
        if (error) {
            console.log('prerenderio error', error); // eslint-disable-line no-console
            return;
        }
    });
    WebApp.rawConnectHandlers.use(prerenderio);
}
});

settings.json

{
 "PrerenderIO": {
    "token": "xxxxxxxxxxxxxx",
    "protocol": "http" //https
},
}

答案 1 :(得分:1)

获得配置选项:

    import { WebApp } from 'meteor/webapp';
    import { Meteor } from 'meteor/meteor';
    import prerenderio from 'prerender-node';

    Meteor.startup(() => {
      prerenderio.set('host', 'localhost:3000');
      prerenderio.set('protocol', 'http');
      prerenderio.set('forwardHeaders', true);
      prerenderio.set('afterRender', function afterRender(error) {
          if (error) {
             console.log('prerenderio error', error);
             return;
          }
     });
     WebApp.rawConnectHandlers.use(prerenderio); 
   });