我正在尝试在Firebase函数中调用本地管理的服务器。我对作为开发环境的节点不是很熟悉,所以我不确定是什么问题。
const functions = require('firebase-functions');
const https = require('http');
exports.testPost = functions.https.onRequest((req, res) => {
var options = {
host: 'localdevserver.edu',
port: 80,
path: '/my/endpoint'
};
let data = '';
http.get(options, function(resp){
resp.on('data', function(chunk){
//do something with chunk
data += chunk;
resp.on('end', console.log("dones"));
});
}).on("error", function(e){
console.log("Got error: " + e.message);
});
});
当我查看Firebase功能日志时,它说超时或未定义拒绝。
答案 0 :(得分:2)
答案 1 :(得分:0)
您可以使用SYNC-REQUEST
npm安装同步请求
var request = require('sync-request');
var res = request('GET', 'http://google.com');
console.log(res.body.toString('utf-8'));
该功能将是这样的:
exports.testPost = functions.https.onRequest((req, res) => {
var request = require('sync-request');
var res = request('GET', 'http://google.com');
var res = res.body.toString('utf-8');
resp.on(res, console.log("dones"));
});