Firebase - npm模块因ENOTFOUND导致崩溃?

时间:2017-11-21 17:34:29

标签: javascript node.js firebase google-cloud-functions

好的,在这里找出带有Firebase云功能的npm并且不确定在哪里转向 -

我需要使用2个NPM模块 - 1个用于获取客户端的ip,另一个用于根据ip吐出位置信息。这些是模块:

https://www.npmjs.com/package/iplocation https://www.npmjs.com/package/external-ip

Firebase每次都需要一段时间才能部署测试功能,因此我开始确保两者都在桌面/终端上使用简单的节点应用程序。在终端中运行node [name of js file],一切都运行良好:

'use strict';

var myIp;
const getIP = require('external-ip')();
var iplocation = require('iplocation');

myIp = getIP((err, ip) => {
    if (err) {
        // every service in the list has failed
        throw err;
    }
    console.log(ip);

    iplocation(ip)
      .then(res => {
        console.log(res);
        /* res:

          {
            as: 'AS11286 KeyBank National Association',
            city: 'Cleveland',
            country: 'United States',
            countryCode: 'US',
            isp: 'KeyBank National Association',
            lat: 41.4875,
            lon: -81.6724,
            org: 'KeyBank National Association',
            query: '156.77.54.32',
            region: 'OH',
            regionName: 'Ohio',
            status: 'success',
            timezone: 'America/New_York',
            zip: '44115'
          }

        */

      })
      .catch(err => {
        console.error(err)
      })
});

然而,当我转到我的firebase应用程序时,把它放进去并转到我的Firebase日志,我得到了这个崩溃

          Error: Multiple errors:   getaddrinfo ENOTFOUND icanhazip.com icanhazip.com:80 from http://icanhazip.com/  
     

getaddrinfo ENOTFOUND ident.me ident.me:80来自http://ident.me/
  来自http://tnx.nl/ip的getaddrinfo ENOTFOUND tnx.nl tnx.nl:80
  getaddrinfo ENOTFOUND myip.dnsomatic.com myip.dnsomatic.com:80 from   http://myip.dnsomatic.com/ getaddrinfo ENOTFOUND ipecho.net   ipecho.net:80来自http://ipecho.net/plain getaddrinfo ENOTFOUND   diagnostic.opendns.com diagnostic.opendns.com:80来自   http://diagnostic.opendns.com/myip

at Object.concatErrors (/user_code/node_modules/external-ip/lib/utils.js:129:12)
at requests.(anonymous function) (/user_code/node_modules/external-ip/lib/extIP.js:34:45)
at get.concat (/user_code/node_modules/external-ip/lib/utils.js:103:24)
at ClientRequest.<anonymous> (/user_code/node_modules/external-ip/node_modules/simple-get/index.js:73:21)

使用:

function returnLocation() {
  myIp = getIP((err, ip) => {
    if (err) {
        // every service in the list has failed
        throw err;
    }
    console.log("THE IP: ", ip);

    iplocation(ip)
      .then(res => {
        console.log(res);
        /* res:

          {
            as: 'AS11286 KeyBank National Association',
            city: 'Cleveland',
            country: 'United States',
            countryCode: 'US',
            isp: 'KeyBank National Association',
            lat: 41.4875,
            lon: -81.6724,
            org: 'KeyBank National Association',
            query: '156.77.54.32',
            region: 'OH',
            regionName: 'Ohio',
            status: 'success',
            timezone: 'America/New_York',
            zip: '44115'
          }

        */

      })
      .catch(err => {
        console.error(err)
      })
});


}
exports.enterLocation = functions.database.ref('/Users/{name}') //brackets is client param
    .onWrite(event => {
      //console.log('SKYLAR HERE:', event.params.name);
      returnLocation();
      //-----------------------------------------

      return event.data.adminRef.set({ location: 'test loc'});
  });

显然我的一个模块或两个模块都调用了http,我知道firebase不喜欢/支持。

这里有什么解决方案?我应该确保我使用的任何依赖项不使用http但https?这甚至是问题吗?

0 个答案:

没有答案