2

I'm trying to run a Flask app in an Azure function to handle a small website. I can't figure out how to get the routing and proxying in Azure to work. Here's the flask app.

import logging

import azure.functions as func
import mimetypes

from flask import Flask, render_template
from azf_wsgi import AzureFunctionsWsgi

app = Flask(__name__)

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/got')
def got():
    return render_template('got.html')

def main(req: func.HttpRequest) -> func.HttpResponse:
    return AzureFunctionsWsgi(app).main(req)

Now what I want to do is route all incoming HTTP requests to my function app to this single function in a way that the paths match the routes in the Flask app. I've tried many different configurations of proxies.json and host.json, but non work.

jshen
  • 11,507
  • 7
  • 37
  • 59

1 Answers1

3

Looks like azf_wsgi is deprecated in favor of official support in Azure Functions for Python. I believe it would be best to switch to that.


You basically have to make 2 changes as documented in the azf_wsgi readme. Here are the same for reference

  1. host.json
{
    "version":  "2.0",
    "extensions": {
        "http": {
            "routePrefix": ""
        }
    }
}
  1. function.json
{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ],
      "route": "app/{*route}"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}
PramodValavala
  • 6,026
  • 1
  • 11
  • 30