diff --git a/week5/app.py b/week5/app.py index ed93707..a5ea79a 100644 --- a/week5/app.py +++ b/week5/app.py @@ -12,7 +12,31 @@ 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 @app.route("/") diff --git a/week5/templates/mosaic.html b/week5/templates/mosaic.html index ee41253..524f9a8 100644 --- a/week5/templates/mosaic.html +++ b/week5/templates/mosaic.html @@ -16,7 +16,7 @@ - {% for image in images %}{% endfor %} + {% for image in images %}{% endfor %}