在1023个字符后,res.render无法正确呈现

时间:2015-12-14 16:55:46

标签: node.js express ghost

我有一个父Express应用程序和一个Ghost应用程序作为子应用程序,在这里使用Ghost作为npm模块。

我将Ghost路由到http://localhost:9000/blog呈现。所有配置都可以正常工作(如果未正确提供基本配置,Ghost将抛出错误。)

这是我的Ghost启动代码

ghost({
  config: path.join(__dirname, '/config/ghost.config.js')
}).then(function (ghostServer) {
  app.use(ghostServer.config.paths.subdir, ghostServer.rootApp);
  ghostServer.start(app);
});

这是我的Ghost配置

// # Ghost Configuration
// Setup your Ghost install for various [environments](http://support.ghost.org/config/#about-environments).

// Ghost runs in `development` mode by default. Full documentation can be found at http://support.ghost.org/config/

var path = require('path'),
    config;

config = {
    // ### Production
    // When running Ghost in the wild, use the production environment.
    // Configure your URL and mail settings here
    production: {
        url: 'http://my-ghost-blog.com',
        mail: {},
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            },
            debug: false
        },

        server: {
            host: '127.0.0.1',
            port: '2368'
        }
    },

    // ### Development **(default)**
    development: {
        // The url to use when providing links to the site, E.g. in RSS and email.
        // Change this to your Ghost blog's published URL.
        url: 'http://localhost:9000/blog/',

        // Example mail config
        // Visit http://support.ghost.org/mail for instructions
        // ```
        //  mail: {
        //      transport: 'SMTP',
        //      options: {
        //          service: 'Mailgun',
        //          auth: {
        //              user: '', // mailgun username
        //              pass: ''  // mailgun password
        //          }
        //      }
        //  },
        // ```

        // #### Database
        // Ghost supports sqlite3 (default), MySQL & PostgreSQL
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '../blog/data/ghost-dev.db')
            },
            debug: false
        },
        // #### Server
        // Can be host & port (default), or socket
        server: {
            // Host to be passed to node's `net.Server#listen()`
            host: '127.0.0.1',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '9000'
        },
        // #### Paths
        // Specify where your content directory lives
        paths: {
            contentPath: path.join(__dirname, '../blog/')
        }
    },

    // **Developers only need to edit below here**

    // ### Testing
    // Used when developing Ghost to run tests and check the health of Ghost
    // Uses a different port number
    testing: {
        url: 'http://127.0.0.1:2369',
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost-test.db')
            }
        },
        server: {
            host: '127.0.0.1',
            port: '2369'
        },
        logging: false
    },

    // ### Testing MySQL
    // Used by Travis - Automated testing run through GitHub
    'testing-mysql': {
        url: 'http://127.0.0.1:2369',
        database: {
            client: 'mysql',
            connection: {
                host     : '127.0.0.1',
                user     : 'root',
                password : '',
                database : 'ghost_testing',
                charset  : 'utf8'
            }
        },
        server: {
            host: '127.0.0.1',
            port: '2369'
        },
        logging: false
    },

    // ### Testing pg
    // Used by Travis - Automated testing run through GitHub
    'testing-pg': {
        url: 'http://127.0.0.1:2369',
        database: {
            client: 'pg',
            connection: {
                host     : '127.0.0.1',
                user     : 'postgres',
                password : '',
                database : 'ghost_testing',
                charset  : 'utf8'
            }
        },
        server: {
            host: '127.0.0.1',
            port: '2369'
        },
        logging: false
    }
};

module.exports = config;

所以基本上,当我去http://localhost:9000/blog时,它根本没有被渲染。没有。我正在使用Chrome并使用Safari进行测试。还测试了没有启用JavaScript的那两个。

然后我尝试curl http://localhost:9000/blog,尝试使用请求者应用程序(如Postman)并返回正确的html字符串。我还尝试使用用户代理作为Chrome和Safari进行curl,它还会返回正确的html。

我追溯到ghost node_modules,渲染器位于此行ghost > core > server > controllers > frontend > index.js中的res.render(view, result)

我将res.render更改为此

res.render(view, result, function(err, string) {
                  console.log("ERR", err);

                  console.log("String", string);

                  res.send(string);
                })

并且没有错误,它会记录当前字符串,但它不会在浏览器上呈现任何内容。

我试过卷曲,邮差,工作,但浏览器不起作用。

然后我尝试发送一个hello world字符串,它起作用,浏览器渲染它。

然后我逐个添加字符串长度,事实证明,任何str.length < 1023都可以由浏览器呈现,但一旦超过它,它就不会。

我尝试在我的父Express应用程序中,它能够发送长度超过1023的字符串,如果我将ghost模块作为独立模块使用,它还能够发送超过1023的字符串。

所以这两者之间肯定发生了一些事情,但我不知道如何调试它。

请帮忙

0 个答案:

没有答案
相关问题