javascript - 使用调度程序 Firebase 云功能检索 IP 地址并存储在 Firestore 中
问题描述
每 30 分钟 Cloud Function 应调用一次(google schedulerCloud Function triggers) 在触发器中,节点代码检索 IP 地址并将其保存在 firestore(firebase)中 每次检索时,它都应存储在 firestore 的当前 IP 字段中。每次都要比较IP。如果 IP 地址相同,则什么也不做。如果 Ip 更改更新当前 ip 并将旧 ip 保存在以前的 IP 中,并列出数组以使用 nodejs 使用 firebase 云功能存储所有新 IP 我当前的代码 index.js 文件
exports.scheduledFunction = functions.pubsub.schedule('every 1 minutes').onRun((context) => {
db.collection("getIpAddress").doc("LA").set({
currIp:request.ip,
prevIp: ""
})
.then(() => {
console.log("Document successfully written!");
})
.catch((error) => {
console.error("Error writing document: ", error);
});
console.log('This will be run every 5 minutes!');
return null;
});
在这段代码中,我收到 request is undefined 错误。
解决方案
推荐阅读
- c++ - 是否可以使用 c++20 的概念来模拟多态性?
- python - 如何创建多情节案例?
- node.js - 模因生成器 node.js discord.js
- r - 将先验信息纳入 R 中的岭回归 (RAPM)
- python - 使用 Visual Studio Code 从 Jupyter 笔记本保存文件时出现 Errno 30
- sql - 从 yyyy-mm-dd 到 mm-yy?
- flutter - Flutter:我们是否被迫在 master 分支上使用 null 安全性?
- notifications - 雪花监控和通知
- forms - Swift UI 表单 - 为什么有这么多空间?
- npgsql - Npgsql 5.0.0.0 事务已完成,不再可用