我是 Firebase Cloud Functions 的新手,一直在努力添加私有 npm 包以使我的函式正常作業。我知道 Firebase 會將它們全部視為公開,除非指定,并且將使用 npm/yarn 安裝我在 package.json 中擁有的內容。
我告訴 Firebase 它是 Github 上的私有存盤庫的唯一方法是添加一個
.npmrc(包含) - 我使用的密鑰是來自 Github-Developers 的個人訪問令牌,它具有所有需要的權限
//npm.pkg.github.com/:_authToken=<access token>
# @calugarul:registry=git https://npm.pkg.github.com/calugarul
@calugarul:registry=git https://<access token>@github.com/kroitor/ccxt.pro.git
在我的 index.js 檔案中,我呼叫了私有存盤庫 (ccxt.pro),但它不會安裝在 Firebase Cloud Functions 服務器上。
索引.js
const functions = require("firebase-functions");
var num = 1;
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
var moment = require('moment');
const ccxtpro = require ('ccxt.pro');
const coinbaseEx = new ccxtpro.coinbasepro({'enableRateLimit': true});
package.json(包含)
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "14"
},
"main": "index.js",
"dependencies": {
"@calugarul/ccxt.pro": "git https://github.com/kroitor/ccxt.pro.git",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.16.0",
"moment": "^2.29.1"
},
"devDependencies": {
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
常見錯誤:
E getTickersAndSendRequestToStart: {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Build failed: npm ERR! Error while executing:\nnpm ERR! /usr/bin/git ls-remote -h -t https://github.com/kroitor/ccxt.pro.git\nnpm ERR! \nnpm ERR! remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.\nnpm ERR! remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.\nnpm ERR! fatal: Authentication failed for 'https://github.com/kroitor/ccxt.pro.git/'\nnpm ERR! \nnpm ERR! exited with error code: 128\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR! /www-data-home/.npm/_logs/2021-10-31T02_03_39_782Z-debug.log; Error ID: beaf8772"},"authenticationInfo":{"principalEmail":"my email"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"projects/smart-trader-cd29f/locations/us-central1/functions/getTickersAndSendRequestToStart"}
macbookpro:functions cleo$
不知道怎么辦,找了好幾天都沒有結果。請幫我找到一種方法來告訴 Firebase 在部署函式時安裝私有存盤庫!
uj5u.com熱心網友回復:
在一天的剩余時間里尋找答案后,這是最簡單但不是最有效的解決方案:
完全忽略了 .npmrc 檔案并在依賴項下的 package.json 中添加了個人訪問令牌,如下所示:<GITHUB_PERSONAL_ACCESS_TOKEN>@github.com
"dependencies": {
"@calugarul/ccxt.pro": "git https://<GITHUB_PERSONAL_ACCESS_TOKEN>@github.com/kroitor/ccxt.pro.git",
"dotenv": "^10.0.0",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.16.0",
"moment": "^2.29.1"
},
它可以作業并且云功能下載私有存盤庫,但這不是安全的方法。如果有人有更安全的方法,請告訴我。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/349148.html
標籤:节点.js 火力基地 github 谷歌云firestore 谷歌云功能
