小编Jua*_*cki的帖子

将运行时更改为 Node.js 10 后,云功能失败

我正在尝试通过云功能进行 firebase 备份。当我使用 Runtime: Node.js 8 时,该函数运行完全正常。但是,由于它很快将被弃用,我现在必须使用 Node.js 10。我的 fcloud 函数现在失败并出现以下错误:

错误:函数执行失败。详细信息:无法读取未定义的属性“charCodeAt”

详细的错误日志:

2020-05-27 11:01:21.820 IST
firestore_export
8kxlp9s867dy
TypeError: Cannot read property 'charCodeAt' of undefined at peg$parsetemplate (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:304:17) at Object.peg$parse [as parse] (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:633:18) at new PathTemplate (/workspace/node_modules/google-gax/build/src/pathTemplate.js:55:54) at segments.forEach.segment (/workspace/node_modules/google-gax/build/src/pathTemplate.js:120:29) at Array.forEach (<anonymous>) at PathTemplate.render (/workspace/node_modules/google-gax/build/src/pathTemplate.js:114:23) at FirestoreAdminClient.databasePath (/workspace/node_modules/@google-cloud/firestore/build/src/v1/firestore_admin_client.js:904:57) at exports.scheduledFirestoreBackup (/workspace/index.js:6:31) at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:330:28) at process._tickCallback (internal/process/next_tick.js:68:7)
Expand all | Collapse all
{
 insertId: "000000-f688386c-8f2b-4146-aaf7-1fe67c656fa2"  

labels: {…}  
 logName: "projects/firestore-249705/logs/cloudfunctions.googleapis.com%2Fcloud-functions"  
 receiveTimestamp: "2020-05-27T05:31:31.171084310Z"  

resource: {…}  
 severity: "ERROR"  
 textPayload: "TypeError: Cannot read …
Run Code Online (Sandbox Code Playgroud)

javascript firebase google-cloud-platform google-cloud-functions google-cloud-firestore

6
推荐指数
2
解决办法
1194
查看次数

Stripe - 创建或更新订阅时 PaymentIntent 为空

我是 Stripe 的新手,所以如果我遗漏了什么,请提供建议。

技术栈:React(前端)节点(后端)

我正在尝试创建或更新 Stripe 订阅,在任何一种情况下,我都会得到一个 null paymentIntent。我想我读到我应该检查 paymentIntent 状态以确保订阅的付款已经完成。

我的订阅工作流程,当用户注册时,我创建一个 Stripe 客户并将他们添加到订阅中。此订阅是免费套餐,因此不需要付款方式。该payment_intent为空。

//create a Stripe customer code here
...

//create the subscription 
const subscription = await stripe.subscriptions.create({
    customer: customer.id,
    items: [{ priceID }],
    expand: ['latest_invoice.payment_intent'],
});

const invoice = subscription.latest_invoice as Stripe.Invoice;
const payment_intent = invoice.payment_intent as Stripe.PaymentIntent;
Run Code Online (Sandbox Code Playgroud)

后来他们想升级到付费计划后,我申请了一张信用卡并将他们当前的订阅升级到付费计划。在前端,我使用 Stripe Element 并通过这样做创建付款方式。

if (!elements || !stripe) {
     return 
}

const cardElement = elements.getElement(CardElement);

if (!cardElement) {
     return
}

// Confirm Card Setup
const { 
     error, 
     paymentMethod …
Run Code Online (Sandbox Code Playgroud)

node.js stripe-payments reactjs

6
推荐指数
1
解决办法
853
查看次数

Firebase-Function - 预定函数不断抛出错误“未经授权”

我正在制作一个“预定的”firebase 函数,它从外部 API 源获取数据并将其保存在 firestore 中。

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const { default: Axios } = require("axios");
admin.initializeApp();

exports.getIndexData = functions.pubsub.schedule('every 5 minutes').onRun(async() => {

  try {
    const response = await Axios(
      "https://financialmodelingprep.com/api/v3/quotes/index?apikey=myAPIKEY"
    );
    const data = response.data;

    const writeResult = await admin
      .firestore()
      .collection("index")
      .doc("sorted-index")
      .set({ indexData: data,timeStamp:Date.now()});

  } catch (error) {
    console.log(error);
  } 
  return null;

});

Run Code Online (Sandbox Code Playgroud)

这是我的 firebase 函数代码。当我单独运行该功能时它完全正常,并且我还使用“谷歌云平台云功能测试”测试了该功能。当我单独运行一个函数时,数据已成功设置在 firestore 中。

但是,当我部署该功能时它不起作用,我认为这是关于计划功能的东西

{
  "insertId": "184t0npf9hhej7",
  "jsonPayload": {
    "pubsubTopic": "projects/my-project/topics/firebase-schedule-getIndexData-us-central1",
    "targetType": "PUB_SUB",
    "status": "UNAUTHENTICATED",
    "jobName": …
Run Code Online (Sandbox Code Playgroud)

javascript node.js firebase google-cloud-platform google-cloud-functions

6
推荐指数
2
解决办法
374
查看次数

如何修复错误:您的应用程序 ID 可能不正确。如果错误仍然存​​在,请联系 support@algolia.com

我想将 cloud firestore 数据发送到 algolia 以启用全文搜索。Firebase 云函数日志显示有关应用程序 ID 的错误。我无法理解这个错误以及如何解决这个问题。

 name: 'RetryError',
  message: 'Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.'
Run Code Online (Sandbox Code Playgroud)

这是我的index.js 文件

exports.addFirestoreDataToAlgolia = 
functions.https.onRequest((req, res) => {
  var arr = [];
  admin.firestore().collection("tags").get()
  .then((docs) => {
    docs.forEach((doc) => {
      let user = doc.data();
      user.objectID = doc.id;
      arr.push(user);
    })
    const client = algoliasearch(ALGOLIA_ID, ALGOLIA_ADMIN_KEY);
    const index = client.initIndex(ALGOLIA_INDEX_NAME);
    return index.saveObjects(arr, (err, content) => {
      if (err) {
        res.status(500);
      }
      else {
        res.status(200).send(content);
      }
    }) …
Run Code Online (Sandbox Code Playgroud)

firebase algolia google-cloud-functions

5
推荐指数
1
解决办法
3569
查看次数