最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I do a GET for Firebase.functions().httpsCallable? - Stack Overflow

programmeradmin4浏览0评论

How do I do a GET for Firebase.functions().httpsCallable? I keep receiving a POST error 404 but this is a GET request to my server. Should I pass in nothing or there is something to change this httpsCallable to get function?

Client

let updateWorkshop = Firebase.functions().httpsCallable('api/update/workshop');

    updateWorkshop({/* nothing */})
      .then(res => {
        console.log(res);

      }, err => {
        console.log(err);

      })

Server

app.get('/v3/update/workshop', asyncMiddleware( async (req, res, next) => {
    let results = await UPDATE_WORKSHOP_DATE.Run()
    res.status(200).json({results: results})
}))

exports.api = FUNCTIONS.https.onRequest(app);

How do I do a GET for Firebase.functions().httpsCallable? I keep receiving a POST error 404 but this is a GET request to my server. Should I pass in nothing or there is something to change this httpsCallable to get function?

Client

let updateWorkshop = Firebase.functions().httpsCallable('api/update/workshop');

    updateWorkshop({/* nothing */})
      .then(res => {
        console.log(res);

      }, err => {
        console.log(err);

      })

Server

app.get('/v3/update/workshop', asyncMiddleware( async (req, res, next) => {
    let results = await UPDATE_WORKSHOP_DATE.Run()
    res.status(200).json({results: results})
}))

exports.api = FUNCTIONS.https.onRequest(app);
Share Improve this question edited Jul 30, 2019 at 9:56 phongyewtong asked Jul 30, 2019 at 7:44 phongyewtongphongyewtong 5,31915 gold badges59 silver badges87 bronze badges 2
  • 1 What exactly are you expecting this to invoke on the backend? This will only work with a named callbable function on the backend, not some arbitrary HTTP endpoint. firebase.google./docs/functions/callable – Doug Stevenson Commented Jul 30, 2019 at 8:07
  • i am trying to do a get request from my server. I testing just using the link on google it works – phongyewtong Commented Jul 30, 2019 at 9:57
Add a ment  | 

1 Answer 1

Reset to default 5

If you are just trying to ping your callable function endpoint, a GET won't work. As you can see from the protocol specification for callable functions, it uses a POST. If you use a GET, it's an error because you're not following the protocol.

发布评论

评论列表(0)

  1. 暂无评论