The function you want to monkey patch is the WSGI application that’s used as an entry point - check the gunicorn or bench serve CLI (via Procfile in dev mode, and supervisor.conf in production).
You can update your supervisor conf to point the path to your newly defined function. Similarly, write a custom command for the developer server. Probably look into writing your own WSGI apps using Werkzeug for references if the Frappe codebase isn’t enough.
But this may not be what you want to do unless you’re well aware of the implications of your custom entrypoint. However, using hooks should be sufficient to extend Frappe to your use case.