'firebase cloud function http request is not working properly?
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)
Solution 1:[1]
app.post("/api/create", async (req, res) => {
start api address with /
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pratik Ranpariya |


