'Azure Functions: serving content for root URL
I have an C# Azure Function project, with a variety of functions.
One of the functions is to serve some HTML content. This function can currently be accessed at /api/home. However, I want to have it triggered for the root / URL.
I have added a proxies.json file in my project:
{
"Home": {
"matchCondition": {
"methods": ["GET"],
"route": "/"
},
"backendUri": "https://localhost:7071/api/home"
}
}
But this still has no effect - it continues to serve up the default Azure Fucntions webpage.
Is there any way to do this?
Solution 1:[1]
I'm afraid you can't use the root path to access this function, because https://localhost:7071/ is always the default page of Azure function:
Below are my verification steps, I will change the path of the function to https://localhost:7071/, but it still displays the default page of Azure function app.
By default, the route for your azure function would be localhost:7071/api/{functionName}
You must have noticed by now that almost all the function routes had /api/ in the route. In case, you wanted to change it, you can change it by modifying the content using the host.json.
You need to add "extensions": { "http": { "routePrefix": "" } } in your host.json:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensions": { "http": { "routePrefix": "" } }
}
Now, your route might look like this:
localhost:7071/{functionName}
You also need to set the Route in the code to "".
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "")] HttpRequest req,
The current route should meet your requirements?
But using this path to access this function still fails, so I think it is invalid to set the path of the Azure function as the root path, and you cannot use it to access your Azure function.
If you deploy to Azure portal, you can try to add "AzureWebJobsDisableHomepage ": true in app settings to disable the homepage of Azure function. I tested it locally and it doesn't seem to work. Azure portal seems to work.
Solution 2:[2]
You can add a Proxy in the proxies.json file to a selected function and re-direct it to the root url like below
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"Proxy1": {
"matchCondition": {
"route": "/"
},
"backendUri": "https://<AnotherApp>.azurewebsites.net/api/<FunctionName>"
}
}
}
This will redirect all the calls to the rool URL to the function with name "<FunctionName>"
Bonus Tip:
If you'd like to remove /api from your URL, you can do so by adding the following code in host.json file
"extensions": {
"http": {
"routePrefix": ""
}
}
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 | |
| Solution 2 |



