node.js - 如何在 Judo 中设置 maxBuffer

标签 node.js seo phantomjs snapshot

我正在使用 Judo.js 为我的 Ember 网络应用程序创建站点地图和 html 快照。对站点上基本 url 的简单测试失败。站点地图生成得很好,但是无论 urlConfig 对象包含多少个 URL(或者页面有多“小”),它都会抛出“stdout maxBuffer exceeded”错误。

首先它记录 Preparing to snapshot: 2(其中 2 是我指定的 url 的数量)。 然后记录 Finished snapshotting: 2 然而,它会“挂起”大约 6 秒并吐出:

 Error: stdout maxBuffer exceeded]
    cmd: 'C:\Windows\\system31\\cmd.exe /s /c "phantom.js c:\\Temp\\visitlakesnapshots\\node_modules\\judo\\lib\\phantomjs-runner.js
 http://www.mywebsite.com/dine" 

我做错了什么?我可以修改 phantom 的 maxBuffer 吗?不过,似乎一页不会超过请求大小。

编辑: 当我只运行一个非常小的页面时......确保它在 200K 以下,它可以工作。我发现 maxBuffer 默认值为 200K 的文档。所以我需要知道如何在使用柔道时增加 maxBuffer 选项。我找到了这个但不确定如何将它合并到我现有的代码中:

var execute = function(command, callback){
    exec(command, {maxBuffer: 1024 * 500}, function(error, stdout, stderr){
           callback(error, stdout); });
};

下面是我用 Node 运行的脚本文件:

var http = require('http');
http.createServer(function (req, res) {
   res.writeHead(200, {'Content-Type': 'text/plain'});
   //res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');


var options = {
   muteWarnings: false,   // mute warnings generated by Judo
    phantomProcs: 5      // Number of PhantomJS processes to run concurrently. Had 1 here, changed to 5...makes no difference.
};

var Judo = require('judo');
var judo = new Judo(options);


var urlConfig = {
    baseUrl: 'http://www.visitlakefl.com',     // The base URL of your site
    siteMapPath: 'E:/Websites/VisitLake/sitemap.xml',  // Sitemap output
    snapshotsDir: 'E:/Websites/VisitLake/Views/Snapshots',
    urls: [
        {
            url: '/',
            siteMap: {   changefreq: 'daily' },
            snapshot: { changefreq: 'daily',filenames: ['index.html','home.html']}
        },
         {
            url: '/play',
            siteMap: {   changefreq: 'daily' },
            snapshot: { changefreq: 'daily',filenames: ['play/index.html']}
        },
        {
           url: '/dine',
           siteMap: {  changefreq: 'daily'},
           snapshot: {changefreq: 'daily',filenames: ['dine/index.html']}
       }
    ]
};


//judo.updateSiteMap(urlConfig, function(err){
    //if (!err) console.log('that was easy!');
//});

judo.createSnapshots(urlConfig, function(err){
    if (!err) { console.log('snapshots created. That was easy!');
           process.exit();
        } else { 
      console.log(err);
           process.exit();
    }
});

最佳答案

我的 PR解决此问题的内容已合并。如果您从 GitHub 获得最新版本的柔道,您现在可以在选项中指定一个 maxBuffer 设置,如下所示:

var options = {
    muteWarnings: false,        // Allows the user to mute warnings generated by Judo
    phantomProcs: 1,            // Number of PhantomJS processes to run concurrently
    maxBuffer: 200*1024         // Max PhantomJS output buffer size
};

var judo = new Judo(options);

一旦您将 maxBuffer 设置为大于您网站上最大页面的值,错误就会消失。

关于node.js - 如何在 Judo 中设置 maxBuffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29476916/

相关文章:

Python 绑定(bind)到 Selenium Webdriver : ActionChain not executing in PhantomJS

javascript - NodeJS 中的动态分块响应

wordpress - .htaccess 规则阻止机器人爬行?

node.js - Twitter 视频媒体上传无法正常工作 : Error: HTTP Error: 400 Bad Request

ajax - Wicket 是否会妨碍 SEO 或搜索引擎的抓取能力?

seo - 为什么我的起始目录中的某些页面没有显示在我的站点地图中?

Phantomjs - 如何填充表单,提交并获取结果?

javascript - PhantomJS 未加载动态内容

javascript - 使用 fetch() 的 POST 请求返回 204 No Content

node.js - 平均 IO : Config validation error JWT_SECRET is required