TandoorRecipes/recipes/wsgi.py
2021-09-28 12:51:49 -05:00

45 lines
1.4 KiB
Python

"""
WSGI config for recipes project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
from django_scopes import scopes_disabled
from cookbook.models import Food, Keyword
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "recipes.settings")
# run fix tree here solves 2 problems:
# 1 if tree sorting is changed from unsorted to sorted ensures that objects are sorted
# 2 if any condition caused the tree to be in an inconsistent state this will fix most problems
with scopes_disabled():
Food.fix_tree(fix_paths=True)
Keyword.fix_tree(fix_paths=True)
_application = get_wsgi_application()
# allows proxy servers to serve application at a subfolder
# NGINX config example is included in nginx/conf.d
def application(environ, start_response):
# http://flask.pocoo.org/snippets/35/
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]
scheme = environ.get('HTTP_X_SCHEME', '')
if scheme:
environ['wsgi.url_scheme'] = scheme
return _application(environ, start_response)