Saturday, 29 April 2017

node.js: req.next is not a function

I've tried to deploy the project to google cloud platform. The code is working fine on my local machine. However, I'm getting the following error on gcloud.

TypeError: req.next is not a function
at done (/app/node_modules/express/lib/response.js:955)
at tryRender (/app/node_modules/express/lib/application.js:641)
at EventEmitter.render (/app/node_modules/express/lib/application.js:591)
at ServerResponse.render (/app/node_modules/express/lib/response.js:960)
at (/app/routes/posts.js:15)
at tryCatcher (/app/node_modules/mongolass/node_modules/bluebird/js/release/util.js:16)
at Promise._settlePromiseFromHandler (/app/node_modules/mongolass/node_modules/bluebird/js/release/promise.js:510)
at Promise._settlePromise (/app/node_modules/mongolass/node_modules/bluebird/js/release/promise.js:567)
at Promise._settlePromise0 (/app/node_modules/mongolass/node_modules/bluebird/js/release/promise.js:612)
at Promise._settlePromises (/app/node_modules/mongolass/node_modules/bluebird/js/release/promise.js:691)
at Async._drainQueue (/app/node_modules/mongolass/node_modules/bluebird/js/release/async.js:138)
at Async._drainQueues (/app/node_modules/mongolass/node_modules/bluebird/js/release/async.js:148)
at Immediate.Async.drainQueues (async.js:17)
at runCallback (timers.js:666)
at tryOnImmediate (timers.js:639)
at processImmediate (timers.js:611)

routes/posts.js:

router.get('/', function(req, res, next) {
  var author = req.query.author;

  PostModel.getPosts(author)
    .then(function (posts) {
      res.render('posts', { //line 15
        posts: posts
      });
    })
    .catch(next);
});

getPosts function:

getPosts: function getPosts(author) {
    var query = {};
    if (author) {
      query.author = author;
    }
    return Post
      .find(query)
      .populate({ path: 'author', model: 'User' })
      .sort({ _id: -1 })
      .addCreatedAt()
      .addCommentsCount()
      .contentToHtml()
      .exec();
  },



via rluo

No comments:

Post a Comment