Firebase functions return 404

我的未来我决定 提交于 2021-01-07 03:13:33

问题


I am trying to set up a custom domain for firebase functions. Custom domain already verified and works fine. My firebase functions run under us-central1:

here is my code for login function:

const functions = require("firebase-functions");
const express = require(`express`);
const cors = require(`cors`);
const admin = require(`firebase-admin`);
admin.initializeApp();

const firestore = admin.firestore();
const appLogin = express();
appLogin.use(cors({origin:true}));

appLogin.post("/", async(req:Request, res:Response)=>{
    functions.logger.log(`received`);
    const body = req.body;
    functions.logger.log(body);
    const result = await firestore.collection(DbCollections.USER).add(body);
    return res.status(201).send(JSON.stringify({"user_id":result.id}));
}); 


exports.login = functions.https.onRequest(appLogin);

nothing super fancy...

So, when I am using url from screenshot in postman - it works fine. But I want to use custom domain like next:

https://mydomai.com/api/login

Here is my firebase.json hosting section:

  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "/api/login",
        "function": "login"
      }
    ]
  }

But when I am trying to reach login with custom domain - it returns me 404 without any valuable error message:

Any ideas?


回答1:


The source of a rewrite is not removed from the URL in the call to the function, so you likely want to change appLogin.post("/", ...) to appLogin.post("/api/login/", ...).



来源:https://stackoverflow.com/questions/64916582/firebase-functions-return-404

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!