我正在撰寫一個 Firestore 函式,我想為其設定一些秘密。我在 firebase 檔案中閱讀了如何設定秘密引數:
https://firebase.google.com/docs/functions/config-env#secret_parameters
所以我這樣嘗試:
import * as functions from "firebase-functions";
import {defineSecret} from 'firebase-functions/params';
const someToken = defineSecret("TOKEN_NAME");
import * as express from "express";
import {bootstrap, services} from "./bootstrap";
export const app = express();
app.use(express.json());
app.get("/", (req, res) => {
res.sendStatus(200);
});
app.post("/", async (req, res) => {
if (!req.body) {
res.send("json body missing!");
return;
}
await bootstrap(someToken.value());
services.useGraphQL?.getEntity(req.body).then(
(response) => {
res.status(200).send(response);
},
() => {
console.error(`Error while ${req.body.command}`);
res.sendStatus(500);
});
}
);
export default functions
.runWith({secrets: ["TOKEN_NAME"]})
.https.onRequest(app);
我的問題/問題是,“someToken.value()”會引發錯誤“'SecretParam' 型別上不存在屬性'值'”。那么我做錯了什么?我該怎么做才能正確地做到這一點?
我試圖以不同的方式讀取 Object 的值,但其他所有問題都解決了更多型別錯誤。
uj5u.com熱心網友回復:
訪問機密時,它們被添加為云功能的環境變數。process.env.MY_SECRET在此示例中可以訪問它們。
另外,您是否對物件進行了 JSON 序列化someToken并記錄了它?這將使您能夠看到物件結構是什么,并且如果上述方法不起作用,則可能會顯示可用的物件鍵。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/521528.html
