firebase / firebase-functions

Firebase SDK for Cloud Functions
https://firebase.google.com/docs/functions/
MIT License
1.01k stars 201 forks source link

Functions stealing OPTIONS requests #1498

Closed daymxn closed 5 months ago

daymxn commented 6 months ago

Related issues

N/A

[REQUIRED] Version info

node: 20.9.0

firebase-functions: 4.5.0

firebase-tools: 12.9.1

firebase-admin: 11.8.0

[REQUIRED] Test case

import { onRequest } from "firebase-functions/v2/https";
import express from "express";

const app = express();

app.all("*", (_, res) => {
  res.sendStatus(200)
})

export const api = onRequest(app);

[REQUIRED] Steps to reproduce

Deploy the given function, and try to make a OPTIONS request.

[REQUIRED] Expected behavior

The response status should be 200.

[REQUIRED] Actual behavior

The response status is 204.

This doesn't seem to be an issue with any other method. My initial assumption is that functions has something intercepting OPTIONS requests for the sake of firebase-auth- but this is not expected behavior for consumers. Especially when folks aren't actually using auth in their underlying implementation. Furthermore, this has been causing a lot of issues on our end in regards to cors configurations.

Were you able to successfully deploy your functions?

Yes

Berlioz commented 5 months ago

Isn't this an Express thing? Your repro is an Express app, which should install a default configuration of its CORS middleware, which looks like it intercepts OPTIONS requests and responds with 204.