Last active
October 23, 2018 14:00
-
-
Save TJM/04ed9bfbec98082eb97fb19242460299 to your computer and use it in GitHub Desktop.
WSGI file for a Dash / Plotly app with no hard coded paths. Picks up the "prefix" for DASH through the WSGI environment variable SCRIPT_NAME and uses the virtualenv "venv"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
my_directory=os.path.dirname(__file__) | |
if my_directory not in sys.path: | |
sys.path.insert(0,my_directory) | |
# Virtual Environment (./venv) | |
activate_this = os.path.join(my_directory, 'venv', 'bin', 'activate_this.py') | |
execfile(activate_this, dict(__file__=activate_this)) | |
from index import app, server | |
# MyDashApp - Calls "server" after setting prefix | |
# SCRIPT_NAME is WSGIScriptAlias | |
class MyDashApp: | |
def __init__(self, application): | |
self.__application = application | |
def __call__(self, environ, start_response): | |
if environ.has_key('SCRIPT_NAME'): | |
prefix = str(environ['SCRIPT_NAME']) | |
if not prefix.endswith('/'): | |
prefix = prefix + '/' | |
app.config.requests_pathname_prefix = prefix | |
app.config.routes_pathname_prefix = prefix | |
return self.__application(environ, start_response) | |
application = MyDashApp(server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *> | |
ServerName localhost.localdomain | |
WSGIDaemonProcess dashboard user=dashboard group=dashboard threads=5 | |
WSGIScriptAlias /dashboard /apps/dashboard/dashboard.wsgi | |
<Directory /apps/dashboard> | |
WSGIProcessGroup dashboard | |
WSGIApplicationGroup %{GLOBAL} | |
Require all granted | |
</Directory> | |
</VirtualHost> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment