Skip to content

Handle browser CORS preflight for extract-isdoc and return CORS headers from function responses#3

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-cors-error-in-azure-function
Draft

Handle browser CORS preflight for extract-isdoc and return CORS headers from function responses#3
Copilot wants to merge 3 commits intomainfrom
copilot/fix-cors-error-in-azure-function

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

Local HTML clients were failing with CORS despite portal-level * configuration because the function endpoint did not handle preflight (OPTIONS) and did not consistently emit CORS headers from application responses.

  • Preflight support at function endpoint

    • Added OPTIONS to the HttpTrigger methods for extract-isdoc.
    • Short-circuits OPTIONS requests with 204 NoContent.
  • Consistent CORS headers from function code

    • Added CORS headers to preflight, success, and error responses:
      • Access-Control-Allow-Origin: *
      • Access-Control-Allow-Methods: POST, OPTIONS
      • Access-Control-Allow-Headers: Content-Type, Authorization, x-functions-key
  • Focused regression coverage

    • Added a unit test asserting the trigger definition includes OPTIONS, preventing accidental removal of preflight support.
[HttpTrigger(AuthorizationLevel.Function, "post", "options", Route = "extract-isdoc")]
public async Task<HttpResponseData> Run(HttpRequestData request)
{
    if (HttpMethods.IsOptions(request.Method))
    {
        var response = request.CreateResponse(HttpStatusCode.NoContent);
        AddCorsHeaders(response);
        return response;
    }

    // existing POST flow...
}

Copilot AI linked an issue May 7, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits May 7, 2026 19:10
Agent-Logs-Url: https://github.com/ITIXO/MKTestAzureFunction/sessions/01d5bcde-4325-402e-8043-2690252b1ce4

Co-authored-by: miroslavkadera <96105189+miroslavkadera@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CORS error in Azure Function Handle browser CORS preflight for extract-isdoc and return CORS headers from function responses May 7, 2026
Copilot AI requested a review from miroslavkadera May 7, 2026 19:14
@miroslavkadera miroslavkadera requested review from Copilot and removed request for miroslavkadera May 7, 2026 19:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds in-function CORS handling for the extract-isdoc HTTP-triggered Azure Function so browser-based clients can successfully complete CORS preflight (OPTIONS) and receive consistent CORS headers across both success and error responses.

Changes:

  • Expanded the extract-isdoc HttpTrigger to include options and short-circuit OPTIONS requests with 204 NoContent.
  • Added a shared helper to attach CORS headers to preflight, success, and error responses.
  • Introduced a unit test to prevent accidental removal of OPTIONS from the trigger definition.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
ExtractIsdocFunction.cs Handles OPTIONS preflight and adds CORS headers to all responses from the function.
tests/MKTestAzureFunction.Tests/ExtractIsdocFunctionTests.cs Adds regression test ensuring the trigger includes OPTIONS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +12 to +17
var runMethod = typeof(ExtractIsdocFunction).GetMethod(nameof(ExtractIsdocFunction.Run));

Assert.NotNull(runMethod);

var requestParameter = runMethod!.GetParameters().Single();
var triggerAttribute = requestParameter.GetCustomAttribute<HttpTriggerAttribute>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CORS error

3 participants