Skip to content

Commit

Permalink
add passenger_wsgi.py for alternate deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jprusik committed Jul 11, 2023
1 parent 4e7a1f3 commit 35844f9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
from datetime import datetime, timezone
from flask import Flask, abort, jsonify, session, redirect, request
from flask_sqlalchemy import SQLAlchemy
from dotenv import load_dotenv
load_dotenv()

flaskApp = Flask(__name__)
flaskApp.config.update(
SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI'),
SQLALCHEMY_TRACK_MODIFICATIONS=os.getenv('SQLALCHEMY_TRACK_MODIFICATIONS'),
SECRET_KEY=os.getenv('SECRET_KEY')
)
ADMIN_USERS = os.getenv('ADMIN_USERS').split(',')

try:
ADMIN_USERS = os.getenv('ADMIN_USERS').split(',')
except:
ADMIN_USERS = []

DEBUG_MODE = os.getenv('DEBUG')
REACT_DOMAIN = os.getenv('REACT_JS_DOMAIN')
MINUTES_EXPIRE = int(os.getenv('SESSION_EXPIRE_MINUTES'))
Expand Down
27 changes: 27 additions & 0 deletions passenger_wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys, os

PYTHON_DIRECTORY = ''
APP_DIRECTORY = ''

# dotenv is not available until the venv Python (with installed packages) replaces the running Python process (via `os.execl` below)
try:
with open('.env') as f:
for line in f:
if line.startswith('PYTHON_DIRECTORY'):
PYTHON_DIRECTORY = line.strip().split('=', 1)[1]
elif line.startswith('APP_DIRECTORY'):
APP_DIRECTORY = line.strip().split('=', 1)[1]
else:
continue
except:
pass

INTERP = os.path.expanduser(PYTHON_DIRECTORY)

# INTERP is present twice so that the new Python interpreter knows the actual executable path
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)

cwd = os.getcwd()
sys.path.insert(0, cwd + APP_DIRECTORY) # You must add your project here

from app import flaskApp as application

0 comments on commit 35844f9

Please sign in to comment.