0

I'm working on an Azure Static Web App and encountering some difficulty with calling Azure Functions from sources other than the Static Web App's Website.

For example, if I have a function /api/FunctionA and another function /api/FunctionB, I'd like to be able to call FunctionB from FunctionA via an HTTP request.

I'm able to do this locally, but trying to do it in production triggers a 401 Unauthorized response. I'm assuming this has something to do with CORS, but I'm not sure if it's possible to configure CORS manually within Static Web Apps. Is there any "official" or recommended way of calling one function from another via HTTP requests? I know about function chaining with Durable Functions, but Durable Functions are not supported in Static Web Apps. And even if they were, it would be overkill for what I'm trying to accomplish. Would appreciate any advice, thank you!

Dustuu
  • 77
  • 2
  • 8

1 Answers1

1

Please check if the below steps help to workaround:

I believe that the calling of one Azure Function from another Azure Function happens in 3 ways:

  1. Send an HTTP Request to another function's public URL.

  2. Put a message into an Azure Queue and let the other Azure Function process it. - This is the best method I believe when both of the functions are in the same Azure Function App. When we define the second function with a Queue Trigger, once an object gets into the queue, the other function gets called automatically and the object gets dequeued.

    Refer here for more information.

  3. Use Durable Functions


if it's possible to configure CORS manually within Static Web Apps

By default, CORS is not supported with static website, but the CORS is handled for Azure Static Web Apps automatically by Azure.

All CORS settings are set up for you by default when you call a Functions endpoint from a static page in an Azure Static Web Apps site.

If you need to set-up the Azure CDN with CORS in Static Web Apps or in HTTP Functions, refer here.