Skip to content
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

Handling wildcard CORS in HttpTrigger function? #764

Closed
craigomatic opened this issue Dec 20, 2021 · 1 comment
Closed

Handling wildcard CORS in HttpTrigger function? #764

craigomatic opened this issue Dec 20, 2021 · 1 comment
Assignees

Comments

@craigomatic
Copy link

I'm building a SaaS solution that uses Azure Functions to host the APIs via HttpTriggers.

For the most part this has worked well, however it seems not possible to support wildcard domains in the Azure portal (see Azure/azure-functions-host#3948), and very annoying to programmatically add them in via the resource manager APIs, so I decided to try the middleware APIs to reuse some of the CORS code from a typical aspnet core project.

I have this in my Program.cs:

.ConfigureServices(services =>
                {
                    services.AddCors(options =>
                    {
                        options.AddPolicy(name: "myorigins",
                            builder =>
                            {
                                builder.WithOrigins("https://*.mydomain.com")
                                    .SetIsOriginAllowedToAllowWildcardSubdomains();
                            });
                    });
)

In a typical aspnet core project I can then app.UseCors("myorigins") later in the bootstrap code - because I couldn't work out how to do this in the function, I've instead created middleware that reuses the CorsService and incorporates the workarounds to access the HttpRequestData/HttpResponseData.

You can see the gist over here: https://gist.github.com/craigomatic/32c24e06262da0d332294075c053298a

Is there a better way to do this?

Ideally, I'd like to reuse the same code pattern as a typical aspnet core app.

@ghost ghost assigned fabiocav Dec 20, 2021
@fabiocav
Copy link
Member

fabiocav commented Jan 4, 2022

This is not really supported today. The portal/ARM configuration are the only supported options at the moment.

Thanks!

@fabiocav fabiocav closed this as completed Jan 4, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Feb 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants