Reputation: 103
I'm facing a 504 error (timeout) when making a request to a Firebase Realtime database
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);
}
}
};
The issue happens here
const snapshot = await db
.ref("properties")
.child(req.query.slug)
.once("value");
I think the vercel app domain (i.e. the staging domain) needs to be added in GCP as an autorised domain, but I can't seem to find out where.
The request works locally (on localhost:3000
) so I assume localhost is allowed in GCP.
Any ideas on how to let a Next JS app on Vercel talk to a Firebase Realtime database without a 504
timeout?
Upvotes: 0
Views: 459
Reputation: 103
Ended up using the Firebase REST api to query firebase realtime database
Upvotes: 0