-
Notifications
You must be signed in to change notification settings - Fork 210
Parameterized configuration of cors from dotenv needs full TypeScript support #1506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I found a few problems with this issue:
|
Hello @CodingDoug. You can use const corsOrigin = defineString('*')
export const hello = onRequest({
cors: corsOrigin.value(),
}, request => {
request.res?.json({hello: 'world'});
}); Does this solve your issue? |
@exaby73 No, it doesn't work because Take, for example, the TypeScript definition of the HttpsOptions object passed to onCreate, and see how it takes various
See that |
I understand your use case here. I will label this as a feature request and let additional insights come in from the team. Thank you :) |
Any update on this? |
Hi @inlined , could we maybe get something similar as you've done in #1538 here for this to be able to configure CORS options for V2 functions based on parameters? In my case I would actually prefer something like this: const isStaging = defineBoolean('STAGING')
const corsOptions = isStaging.value() ? ["stagingcors..."] : ["prodcors..."]
export const myFn = onCall(
{
cors: corsOptions,
},
...
) However, I understand why that's probably not possible so I would also be fine with something like this as @CodingDoug proposed: const corsOptions = defineString('corsoptions') // if that string can define a regex
export const myFn = onCall(
{
cors: corsOptions,
},
...
) |
Strange. This issue was never escalated to the team. I can take a look. |
Version info
node: 18
firebase-functions: 4.5.0
firebase-tools: 13.0.2
[REQUIRED] Steps to reproduce
firebase-functions lacks the correct TypeScript types to do what is stated in the documentation for parameterized configuration. If you try the example code:
TypeScript will fail at compilation with an error like this:
cors is missing a unioned type for
Expression<string>
like the other string configurations:So it seems impossible to configure cors this way (at least from a compilation perspective - perhaps at runtime the JavaScript will still try to eval a provided
StringParam
using a hack likecorsOrigin as unknown as string
?).Secondly, cors takes RegExp and string arrays, and it would be great to be able to configure it using those variants as well. Cors config can vary greatly based on deployment environment.
The text was updated successfully, but these errors were encountered: