Вызов Azure API из Google Cloud Function

Я разработал функцию Google Cloud, которая вызывает API, размещенный в AZURE. Однако функция возвращает ошибку

Ошибка: произошел сбой функции. Подробности: getaddrinfo ENOTFOUND https://bupanonproduction.azure-api.net https://bupanonproduction.azure-api.net:443

Ниже представлена ​​облачная функция Google.

'use strict';
const http = require('https');
const host = 'https://bupanonproduction.azure-api.net';
exports.remaininglimits = (req, res) => {
  // Call the API
  callRemainingLimitsApi().then((output) => {
    // Return the results from the API to API.AI
    res.setHeader('Content-Type', 'application/json');
    res.send(JSON.stringify({ 'speech': output, 'displayText': output }));
  }).catch((error) => {     
        // If there is an error let the user know
    res.setHeader('Content-Type', 'application/json');
    res.send(JSON.stringify({ 'speech': error, 'displayText': error }));
  });
};
function callRemainingLimitsApi () {
  return new Promise((resolve, reject) => {
    // Create the path for the HTTP request to get the weather
    let path = '/api/Values';
    console.log('API Request: ' + host + path);
    // Make the HTTP request to get the weather
    http.get({host: host, path: path, headers: {'Ocp-Apim-Subscription-Key':'0a6e2fa822ec4d7a821d7f286abb6990'}}, (res) => {
         let body = ''; // var to store the response chunks
      res.on('data', (d) => { body += d; }); // store each response chunk
      res.on('end', () => {
        // After all the data has been received parse the JSON for desired data
        let response = JSON.parse(body);
        let jasonString = JSON.stringify(response);
        // Create response
        let output = `Hi, your limit is ${jasonString}.`;
        // Resolve the promise with the output text
        console.log(output);
        resolve(output);
      });
      res.on('error', (error) => {
        reject(error);
      });
    });
  });
}

Когда я использую другой общедоступный API, как показано ниже, он возвращает правильный результат в облачную функцию.

https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=demo

Есть идеи, почему облачная функция не распознает URL-адрес API AZURE?

-Алан-


comment
Возможный дубликат Облачные функции для Firebase — getaddrinfo ENOTFOUND   -  person Doug Stevenson    schedule 06.03.2018
comment
Чтобы отправлять исходящий сетевой трафик в пункты назначения, которые не контролируются Google, вам необходимо выбрать тарифный план.   -  person Doug Stevenson    schedule 06.03.2018
comment
@DougStevenson, как этот API (alphavantage.co/) может вернуть результаты?   -  person Alan B    schedule 06.03.2018


Ответы (1)


Я только что узнал, что хост должен быть определен без префикса «https». Это решило проблему. Я использую бесплатную пробную версию с балансом в 300 долларов и не уверен, считается ли это платным планом.

person Alan B    schedule 06.03.2018