使用Connect js res.render不是一种方法

时间:2012-10-11 09:05:24

标签: javascript node.js express connect dust.js

我编写了通过图形API获取Facebook详细信息的代码。我收到来自facebook API的回复,但我无法将这些回复呈现给我的DUST模板。

下面用于渲染DUST模板的代码。

res.render('listme', me);

我收到以下错误:

  c:\Users\rksbala\node_modules\facebook-sdk\example\connect.js:53
              res.render('listme', me);
                  ^
    TypeError: Object #<ServerResponse> has no method 'render'
        at c:\Users\bradha\node_modules\facebook-sdk\example\connect.js:53:15
        at Facebook._graph (c:\Users\bradha\node_modules\facebook-sdk\lib\facebook.js:459:21)
        at IncomingMessage.Facebook._makeRequest.FacebookApiException.error_code (c:\Users\bradha\node_modules\facebook-sdk\lib\facebook.js:529:9)
        at IncomingMessage.EventEmitter.emit (events.js:115:20)
        at IncomingMessage._emitEnd (http.js:366:10)
        at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)
        at CleartextStream.socketOnData [as ondata] (http.js:1366:20)
        at CleartextStream.CryptoStream._push (tls.js:492:27)
        at SecurePair.cycle (tls.js:846:20)
        at EncryptedStream.CryptoStream.write (tls.js:227:13)  

app.js代码:

 var express = require('express')
          , routes = require('routes')
          , http = require('http')
          , dust = require('dustjs-linkedin')
          , cons = require('consolidate')
          , path = require('path')
          , connect = require('connect')
          , fbsdk = require('facebook-sdk');


        var port = 8000;

        connect()
          .use(connect.favicon())
          .use(connect.cookieParser())
          .use(connect.bodyParser())
          .use(connect.methodOverride())
          .use(fbsdk.facebook({
            appId  : 'XXXXXXXXXXXXXXXXXXX',
            secret : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
          }))

          .use(function(req, res, next) {
            var model = {title: 'PayPal :: Add Credit Card'};
            if (req.facebook.getSession()) {

              // get my graph api information
              req.facebook.api('/me', function(me) {
                var model;              
                if (me.error) {
                  res.end('An api error occured, so probably you logged out. Refresh to try it again...');
                } else {                 
                  res.render('listme', me);
                 //console.log(res);
                }
              });

            } else {
              res.end('<a href="' + req.facebook.getLoginUrl() + '">Login</a>');
            } 
          })
          .listen(port);

        console.log('Listening for http requests on port ' + port);

请让我知道我做了什么错误。

0 个答案:

没有答案