adding gunicorn magic

master
xpub1 1 year ago
parent 6307605d46
commit 2553ad099b

@ -0,0 +1,10 @@
include .env
export
default: local
local:
@flask run --debug
breadcube:
@SCRIPT_NAME=${OVERLAP_APPLICATION_ROOT} gunicorn -b localhost:${OVERLAP_PORTNUMBER} --reload app:app

@ -12,33 +12,16 @@ def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
# Kamo's prefix to add /soupboat/padliography to all the routes
class PrefixMiddleware(object):
def __init__(self, app, prefix=""):
self.app = app
self.prefix = prefix
def __call__(self, environ, start_response):
if environ["PATH_INFO"].startswith(self.prefix):
environ["PATH_INFO"] = environ["PATH_INFO"][len(self.prefix):]
environ["SCRIPT_NAME"] = self.prefix
return self.app(environ, start_response)
else:
start_response("404", [("Content-Type", "text/plain")])
return ["This url does not belong to the app.".encode()]
# create flask application
app = Flask(__name__)
# Get the URL prefix for the soupboat
# register the middleware to use our base_url as prefix on all the requests
base_url = os.environ.get('BASE_URL', '')
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=base_url)
# configure the upload folder
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# load the settings of the applicaiton
# (to handle the routing correctly)
app.config.from_pyfile('settings.py')
@app.route("/")
def overlap():
images = glob.glob('./static/img/*.png')

@ -0,0 +1,4 @@
Flask==2.3.2
gunicorn==20.1.0
Jinja2==3.1.2
python-dotenv==1.0.0

@ -0,0 +1,10 @@
import os
from dotenv import main
# Load environment variables from the .env file
main.load_dotenv()
# Bind them to Python variables
APPLICATION_ROOT = os.environ.get('OVERLAP_APPLICATION_ROOT', '/')
PORTNUMBER = int(os.environ.get('OVERLAP_PORTNUMBER', 5001))
Loading…
Cancel
Save