'Azure function accessible locally only

I have an Azure static web app with a svelte front end and azure server less functions for backend. When developing locally I can connect to the functions perfectly with fetch(‘https://localhost:7071/api/test’) But when I replace it with fetch(‘/api/test’) it won’t work locally or on the deployed site.



Solution 1:[1]

Yes! As Lokanath Das said, Root URL + Route makes an API URL.

In The Azure Functions Scenario: When you run locally, the root URL is combination of localhost, port number and the route (api/function_name).

enter image description here

When you run in the Cloud, then the URL will be: "https://<azurefunctionappname>.azurewebsites.net/api/<FunctionName>" .

We can customize the Azure Function URL Route using HTTP Route Trigger Parameters and can make them optional or we can define the route in the Azure Function Header. Refer here for more information

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HariKrishnaRajoli-MT