From ca4dc1db8bc135c61bdc34a25cfc306b01242625 Mon Sep 17 00:00:00 2001 From: Tomi Belan Date: Tue, 14 Nov 2023 00:30:48 +0100 Subject: [PATCH] Add "staticized_application" for manual testing with gunicorn. Run it like this: ./venv/bin/gunicorn -w 3 -b localhost:5000 console:staticized_application --- console.py | 1 + votrfront/app.py | 10 ++++------ votrfront/serve.py | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/console.py b/console.py index d79386d..2e44558 100755 --- a/console.py +++ b/console.py @@ -12,6 +12,7 @@ application = VotrApp(settings=settings) proxied_application = ProxiedMiddleware(application) + staticized_application = VotrApp.wrap_static(application) except Exception: import os, sys, time, traceback if not (__name__ == '__main__' and os.getenv('WERKZEUG_RUN_MAIN')): raise diff --git a/votrfront/app.py b/votrfront/app.py index 981d148..dc679df 100644 --- a/votrfront/app.py +++ b/votrfront/app.py @@ -57,7 +57,7 @@ def dispatch_request(self, request): return e @Request.application - def wsgi_app(self, request): + def __call__(self, request): '''Main WSGI entry point.''' request.app = self @@ -70,15 +70,13 @@ def wsgi_app(self, request): return response - def wrap_static(self): + @staticmethod + def wrap_static(app): '''Adds a "/static" route for static files. This should only be used for the development server. Production servers should expose the /static directory directly. ''' - self.wsgi_app = SharedDataMiddleware(self.wsgi_app, { + return SharedDataMiddleware(app, { '/static': os.path.join(os.path.dirname(__file__), 'static') }) - - def __call__(self, *args): - return self.wsgi_app(*args) diff --git a/votrfront/serve.py b/votrfront/serve.py index bcc8ddc..e21fb18 100644 --- a/votrfront/serve.py +++ b/votrfront/serve.py @@ -41,8 +41,8 @@ def serve(app, *args): else: ssl_context = None - app.wrap_static() - run_simple(bind, port, app, ssl_context=ssl_context, + app_with_static = type(app).wrap_static(app) + run_simple(bind, port, app_with_static, ssl_context=ssl_context, use_debugger=debug, use_reloader=True, threaded=True) serve.help = ' $0 serve [--debug] [--https] [--bind=X.X.X.X] [--port=N]'