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 bf73781..0000000 Binary files a/week5/__pycache__/app.cpython-310.pyc and /dev/null differ 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)) +