Skip to content

Commit

Permalink
Add "staticized_application" for manual testing with gunicorn.
Browse files Browse the repository at this point in the history
Run it like this:

    ./venv/bin/gunicorn -w 3 -b localhost:5000 console:staticized_application
  • Loading branch information
TomiBelan committed Nov 13, 2023
1 parent 23a0f89 commit ca4dc1d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions votrfront/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
4 changes: 2 additions & 2 deletions votrfront/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down

0 comments on commit ca4dc1d

Please sign in to comment.