From 2553ad099b3cb53d0dcdd259238e3ef59fe9d17d Mon Sep 17 00:00:00 2001 From: xpub1 Date: Tue, 30 May 2023 19:52:02 +0200 Subject: [PATCH] adding gunicorn magic --- week5/Makefile | 10 ++++++++++ week5/__pycache__/app.cpython-310.pyc | Bin 1348 -> 0 bytes week5/app.py | 25 ++++--------------------- week5/requirements.txt | 4 ++++ week5/settings.py | 10 ++++++++++ 5 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 week5/Makefile delete mode 100644 week5/__pycache__/app.cpython-310.pyc create mode 100644 week5/requirements.txt create mode 100644 week5/settings.py diff --git a/week5/Makefile b/week5/Makefile new file mode 100644 index 0000000..e505351 --- /dev/null +++ b/week5/Makefile @@ -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 diff --git a/week5/__pycache__/app.cpython-310.pyc b/week5/__pycache__/app.cpython-310.pyc deleted file mode 100644 index bf737818b42003efe9c8af7c5703136b7de1939c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1348 zcmZ8g&2QT_6z8KTS(ZPOZo#q*TMk75?_i+?b}NdtO$rnU>|k!NLKj0dX-AG^X(Zz; zhI4WcyYxPwC}3l!{!6^>)IVUCUbaVh80u2s)B7MF-}~{$ywL~O&%G>jn=tz-zqznqaJn`y1Oc0Hf0eZ}Qdzc>4|IdwjoK)8cGE zI(I%`b)*BveU`@RvO`TpieImU(#Ds9CsK?wMq5(MxR66FvLcPO=q(!EQ0Z7FqcF)P z;Uf>TM9w4`N6xgEL{7oS#?ilN)Mk^2O$#v@fj#QKVRehpQ=IAu1&1Y>lf1PgYt%X2 zP)-lY8a71JIl)Suo`LQMyRYLIPpTqKv~kn?T1d11`1G{@%gOQZOoj)982T)@6em zxFs4}ULhegwz?$Tc|);H)?4iFK>I@%5nR-=T*b+#d!e)RJw#rT#S@_r2{uXdSH>-5 zGSd=yNaVg1w%@I2qGl@jT*x#oY^-b`pgz>8{1WXBNC$t5N_bVIdCUzv>knQaew9q< zi=3;Se(X|uq-9vIqbpIw$PF$4lJ+Us z%e2|HdA_pAKD))*_JT?(euHsk`weISP3l1aU*kN0Hu#kNE$`ZlZLH5eYe{W3dv)bW zTb|sp=C@W@aHQq-meBriXkX26D8IM9BNWD!`IQzWU&_>RyvJ;a}piHoyP? diff --git a/week5/app.py b/week5/app.py index a5ea79a..41ac33c 100644 --- a/week5/app.py +++ b/week5/app.py @@ -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') diff --git a/week5/requirements.txt b/week5/requirements.txt new file mode 100644 index 0000000..e51be0a --- /dev/null +++ b/week5/requirements.txt @@ -0,0 +1,4 @@ +Flask==2.3.2 +gunicorn==20.1.0 +Jinja2==3.1.2 +python-dotenv==1.0.0 diff --git a/week5/settings.py b/week5/settings.py new file mode 100644 index 0000000..71c9f76 --- /dev/null +++ b/week5/settings.py @@ -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)) +