3

I have a javascript web application written in React which is using the Firebase SDK to make calls to my Firebase Cloud Functions written in Node 8. For simplicity, the code looks like this:

API index.js

module.exports.test = functions.https.onCall((data, context) => {
   return 'Finished'
})

React code

app.functions().httpsCallable('test')().then(console.log)

The code itself works great, however when looking at the logs, I can see 2 invocations.

Function call 1

Function call 2

This seems to be from the CORS preflight request the browser is making before making the actual call.

Am I charged for this preflight request invocation, and how can I prevent it (if at all)? Are there any headers or settings I can add either client or function side to ensure that my function invocation quota is essentially halved?

plusheen
  • 593
  • 2
  • 12
  • 1
    Possible duplicate of [Firebase Cloud Functions https.onCall finished with status code: 204](https://stackoverflow.com/questions/49931587/firebase-cloud-functions-https-oncall-finished-with-status-code-204) – zkohi Jun 13 '19 at 12:05
  • @zkohi This indeed matches the scenario I am experiencing, I will edit my question as I am more interested in hopefully disabling the preflight request as I do not wish to be charged for these calls. – plusheen Jun 13 '19 at 12:51
  • 1
    The reference is https://firebase.google.com/docs/functions/callable-reference . `In JavaScript clients, these requests trigger a CORS OPTIONS preflight `. I don't know that preflight request invocation is charged or not. But I think the preflight request is always triggered and charged. – zkohi Jun 13 '19 at 13:21
  • Ahh I didn't find this documentation. Thank you. As a follow up - I imagine the preflight request will be delayed by a cold start of the instance. Would this mean all follow up request will never be delayed by a cold start, and the instance invocation time displayed in the logs will always reflect the time taken to execute the function? (I am having optimisation issues as you can see in my timings and wish to narrow down what is cold start and what isnt) – plusheen Jun 13 '19 at 13:47
  • I think the instance invocation time displayed in the logs will always reflect the time taken to only execute the function. – zkohi Jun 13 '19 at 15:03
  • Interesting, the example in my question is a genuine one, an OPTIONS request taking 700ms seems like something is fishy. I'd chalk it up to an unoptomised code on my part, but`onCall` says it handles OPTIONS requests itself. Could also be a region thing I guess (functions are us central, i'm eu west). – plusheen Jun 13 '19 at 15:23

0 Answers0