2016-03-22 23:41:04 +03:00
|
|
|
# flake8: noqa
|
|
|
|
import os
|
|
|
|
|
|
|
|
from decouple import config
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
import newrelic.agent
|
|
|
|
except ImportError:
|
|
|
|
newrelic = False
|
|
|
|
|
|
|
|
|
|
|
|
if newrelic:
|
|
|
|
newrelic_ini = config('NEWRELIC_PYTHON_INI_FILE', default=False)
|
|
|
|
if newrelic_ini:
|
|
|
|
newrelic.agent.initialize(newrelic_ini)
|
|
|
|
else:
|
|
|
|
newrelic = False
|
|
|
|
|
2017-05-04 21:23:54 +03:00
|
|
|
IS_HTTPS = os.environ.get('HTTPS', '').strip() == 'on'
|
2016-03-22 23:41:04 +03:00
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bedrock.settings')
|
|
|
|
|
|
|
|
# must be imported after env var is set above.
|
2017-05-04 21:23:54 +03:00
|
|
|
from django.core.handlers.wsgi import WSGIRequest
|
2016-03-22 23:41:04 +03:00
|
|
|
from django.core.wsgi import get_wsgi_application
|
2016-08-25 17:16:33 +03:00
|
|
|
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
|
2016-03-22 23:41:04 +03:00
|
|
|
|
2017-05-04 21:23:54 +03:00
|
|
|
|
|
|
|
class WSGIHTTPSRequest(WSGIRequest):
|
|
|
|
def _get_scheme(self):
|
|
|
|
if IS_HTTPS:
|
|
|
|
return 'https'
|
|
|
|
|
|
|
|
return super(WSGIHTTPSRequest, self)._get_scheme()
|
|
|
|
|
2016-03-22 23:41:04 +03:00
|
|
|
application = get_wsgi_application()
|
2017-05-04 21:23:54 +03:00
|
|
|
application.request_class = WSGIHTTPSRequest
|
2016-08-25 17:16:33 +03:00
|
|
|
application = Sentry(application)
|
2016-03-22 23:41:04 +03:00
|
|
|
|
|
|
|
if newrelic:
|
|
|
|
application = newrelic.agent.wsgi_application()(application)
|