Skip to content

WsgiFunctionApp with DispatcherMiddleware and registering new HTTP triggers blueprints #213

Closed
@mycaule

Description

@mycaule

Using a technique called DispatcherMiddleware it is possible to mount a Flask app only at an arbitrary prefix path.

Would it be possible for the http_app_func to manage only this mount path so that the app can register other HTTP endpoints (using durable functions and orchestrators for example)

import azure.functions as func
from werkzeug.serving import run_simple
from werkzeug.middleware.dispatcher import DispatcherMiddleware

flask_app = Flask(__name__)
@flask_app.get("/")
def hello():
    return Response(f"<h1>Hello World</h1>", mimetype="text/html")

flask_app.wsgi_app = DispatcherMiddleware(run_simple, {'/abc/123': flask_app.wsgi_app})
# see https://stackoverflow.com/a/18967744/1360476

app = func.WsgiFunctionApp(app=flask_app.wsgi_app, http_auth_level=func.AuthLevel.ANONYMOUS)
# app.register_blueprint(other_http_bp_here)

It appears every routes become managed by http_app_func because of the constant route template below.

@self.http_type(http_type='wsgi')
@self.route(methods=(method for method in HttpMethod),
auth_level=self.auth_level,
route="/{*route}")
def http_app_func(req: HttpRequest, context: Context):
return wsgi_middleware.handle(req, context)

Moreover using the host.json file it looks like it is only possible to set the $.extensions.http.routePrefix globally

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook?tabs=isolated-process%2Cfunctionsv2&pivots=programming-language-python#hostjson-settings

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions