firebase / firebase/firebase-functions
Params CompareExpression `.thenElse` does not support `RegExp` as value, therefore disallows the use of RegExp values for CORS options
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 232
- Avg merge
- 20h 46m
- Merged PRs (30d)
- 15
Description
### Related issues
#1787
#1406
#1903
Actually I am trying to do this https://github.com/firebase/firebase-functions/pull/1903#issuecomment-5105925317 - however it turned out that #1903 unfortunately does not support setting regex CORS options directly from the .env files.
### [REQUIRED] Version info
**node:** v24.18.0
**firebase-functions:** v7.3.0
**firebase-tools:** v15.23.0
**firebase-admin:** v13.10.0
### [REQUIRED] Test case
```typescript
const environmentVariable_Some = defineBoolean('SOME')
const environmentVariable_Staging = defineBoolean('IS_STAGING')
const corsOptionsLocal = [/^http:\/\/localhost:808[0|1]$/]
const corsOptionsStaging = [/^https:\/\/(staging|otherstaging)\.example\.com$/]
const corsOptionsProduction = [/^https:\/\/(some|other)\.example\.com$/]
const corsOptions = environmentVariable_Some
.equals(true)
.thenElse(corsOptionsLocal, environmentVariable_Staging.equals(true).thenElse(corsOptionsStaging, corsOptionsProduction))
export const myFn = onCall(
{
cors: corsOptions
},
async () => {
...
}
```
### [REQUIRED] Steps to reproduce
1. Run `npx tsc`
### [REQUIRED] Expected behavior
I can set dynamic (RegExp-based) allowed CORS hosts dynamically depending on the environment.
The `onCall` `cors` option allows the following types:
```
(property) HttpsOptions.cors?: string | boolean | RegExp | Expression | Expression | (string | RegExp)[] | undefined
```
...so it should also be possible to create a `Expression` using the `.equals(xx).thenElse(...)` `CompareExpression` helper.
### [REQUIRED] Actual behavior
```
Argument of type 'RegExp[]' is not assignable to parameter of type 'string | number | boolean | string[] | Expression'.
Type 'RegExp[]' is not assignable to type 'string[]'.
Type 'RegExp' is not assignable to type 'string'.
```
### Were you able to successfully deploy your functions?
No
Contributor guide
Assessment
This issue has not been assessed yet.