【问题标题】:504 timeout when querying Firebase Realtime Database in Next JS / Vercel在 Next JS / Vercel 中查询 Firebase 实时数据库时出现 504 超时
【发布时间】:2021-06-17 04:18:53
【问题描述】:

向 Firebase 实时数据库发出请求时遇到 504 错误(超时)

import admin from "firebase-admin";

if (!admin.apps.length) {
  admin.initializeApp({
    credential: admin.credential.cert({
      project_id: process.env.FIREBASE_PROJECT_ID,
      private_key: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'),
      client_email: process.env.FIREBASE_CLIENT_EMAIL,
    }),
    databaseURL: process.env.FIREBASE_DATABASE,
  });
}

const db = admin.database();

export default async (req, res) => {
  if (req.method === "GET") {
    try {
      const snapshot = await db
      .ref("properties")
      .child(req.query.slug)
      .once("value");
      
      const properties = snapshot.val();

      return res.status(200).json({ total: properties });
    } catch(e) {
      console.error(e);
    }
  }

};

问题发生在这里

const snapshot = await db
    .ref("properties")
    .child(req.query.slug)
    .once("value");

我认为 vercel 应用程序域(即暂存域)需要作为自动域添加到 GCP 中,但我似乎无法找出在哪里。

请求在本地工作(在 localhost:3000 上),所以我假设 GCP 中允许 localhost。

关于如何让 Vercel 上的 Next JS 应用程序与 Firebase 实时数据库对话,而不会出现 504 超时?

【问题讨论】:

    标签: firebase-realtime-database next.js vercel


    【解决方案1】:

    最终使用 Firebase REST api 查询 firebase 实时数据库

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-02
      • 2019-07-31
      • 1970-01-01
      • 1970-01-01
      • 2020-12-02
      • 1970-01-01
      • 2018-09-14
      相关资源
      最近更新 更多