2014-05-20 76 views
1

我使用MeanJs使用MEAN堆棧。問題是,我有一個任務需要從服務器端(Expressjs)調用GET請求到另一個服務器(使用不同的域名)。使用MEAN堆棧從服務器控制器獲取請求

在客戶端的代碼(AngularJs)稱:

$scope.getWorkflow = function() { 
    $http.get('/ezee', $scope.credentials).success(function(response) { 
      console.log(response.message); 
     }).error(function(response) { 
      console.log('error'); 
     }); 
}; 

以及相應的服務器控制器的功能是:

exports.list = function(req, res) { 
    req.get('http://ezslave.io', function(q, r){ 
     res.json({message: r.message}); // just to test 
    }); 
}; 

顯然,下面的代碼無法正常工作。我不確定如何從list函數發出GET請求。我是否應該爲此使用ExpressJs或純粹的NodeJs?以及如何獲得正確的庫加載?

+0

我剛開始用Node.js的打算,所以我不能自信地回答,但我敢肯定這是你要找的內容:HTTP: //nodejs.org/api/http.html#http_http_get_options_callback –

回答

1

使用nodejs的請求模塊:https://github.com/mikeal/request 發送http請求。

var request = require("request"); 

exports.list = function(req, res) { 
     request("http://ezslave.io",function(err,response,body){ 
      res.send(response); 
    });   
    }; 

希望這有助於你

相關問題