Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Writing an Azure Function that serves all traffic to a subdomain#
Azure Functions default to serving traffic from a path like /api/FunctionName - for example https://your-subdomain.azurewebsites.net/api/MyFunction.
If you want to serve an entire website through a single function (e.g. using Datasette) you need that function to we called for any traffic to that subdomain.
Here’s how to do that - to capture all traffic to any path under https://your-subdomain.azurewebsites.net/.
First add the following section to your host.json file:
1 "extensions": {2 "http": {3 "routePrefix": ""4 }5 }Then add "route": "{*route}" to the function.json file for the function that you would like to serve all traffic. Mine ended up looking like this:
1{2 "scriptFile": "__init__.py",3 "bindings": [4 {5 "authLevel": "Anonymous",6 "type": "httpTrigger",7 "direction": "in",8 "name": "req",9 "route": "{*route}",10 "methods": [11 "get",12 "post"13 ]14 },15 {16 "type": "http",17 "direction": "out",18 "name": "$return"19 }20 ]21}See https://github.com/simonw/azure-functions-datasette for an example that uses this pattern.