gpt4 book ai didi

node.js - 代理服务器后面的 Firebase/NodeJS

转载 作者:太空宇宙 更新时间:2023-11-03 23:26:46 28 4
gpt4 key购买 nike

当计算机位于公司代理后面时,如何在 NodeJS 上运行 Firebase 管理?

npm 已经配置了代理和 https-proxy。 npm 命令执行正常。

但是,Firebase 尝试直接访问互联网:

Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "connect ETIMEDOUT 216.58.203.45:443".

我尝试更新firebase-admin下的faye-websocket\lib\faye\websocket\client.js来读取

  var Client = function(_url, protocols, options) {
options = options || {};
options.proxy = {
origin: 'http://proxy.server.local:8080'
};

我尝试了几种变体,但nodejs仍然尝试直接访问216.58.203.45:443。我还应该更新哪些内容才能使其正常工作?

最佳答案

这就是我在公司代理后面运行 FirebaseAdmin 的方式。

请安装最新的 Firebase 管理 Node 版本,即 v6.4.0 及更高版本。此外,您还需要安装tunnel2库。

npm install firebase-admin@6.4.0
npm install tunnel2


var admin = require('firebase-admin');
var serviceAccount = require('path/to/serviceAccountKey.json');
const tunnel = require('tunnel2')
// Create your Proxy Agent
// Please choose your tunneling method accordingly, my case
// is httpsoverHttp, yours might be httpsoverHttps
const proxyAgent = tunnel.httpsOverHttp({
proxy: {
host: 'yourProxyHost',
port: yourProxyPort,
proxyAuth: 'user:password' // Optional, required only if your proxy require authentication
}
});
admin.initializeApp({
credential: admin.credential.cert(serviceAccount, proxyAgent),
databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'
});

希望对您有帮助。我为此写了一篇文章。你可以引用那里 the article here

关于node.js - 代理服务器后面的 Firebase/NodeJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43107493/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com