Reputation: 85
My cloud functions API is not working properly when I hit api on postman, there are no error, just getting 404 on postman. Code and screenshots are attached.
index.js
const functions = require("firebase-functions");
const admin = require("firebase-admin");
var serviceAccount = require("./key.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
const express = require("express");
const cors = require("cors");
// main app
const app = express();
app.use(cors({ origin: true }))
// main database refference
const db = admin.firestore();
// Routes test
app.get("/", (req, res) => {
return res.status(200).send("test api ")
})
// create
app.post("api/create", async (req, res) => {
console.log(req)
try {
console.log(req)
await db.collection(useDetails).doc(`/${Date.now()}/`).create({
id: Date.now(),
name: req.body.name,
mobile: req.body.mobile,
add: req.body.add
})
return res.status(200).send({ status: "Sucess", msg: "Data Saved" });
} catch (error) {
console.log(error)
return res.status(200).send({ status: "Failed", msg: "Data not Saved" });
}
})
exports.app = functions.https.onRequest(app)
Firebase Emulator is also working fine
when I hit api on postman here is the response i get
Upvotes: 0
Views: 1047
Reputation: 121
app.post("/api/create", async (req, res) => {
start api address with /
Upvotes: 1