diff --git a/.gitignore b/.gitignore index 769e5e2..32414aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ venv/ .DS_Store +__pycache__ \ No newline at end of file diff --git a/main.py b/main.py index c53d417..0ebb5bf 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,10 @@ from flask import Flask, render_template, send_from_directory from markdown import markdown +from prefix import PrefixMiddleware app = Flask(__name__) +app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/soupboat/wlist') + @app.route('/') def list(): @@ -14,4 +17,4 @@ def list(): def send_img(file): return send_from_directory(app.root_path + '/img/', file, conditional=True) -app.run(port="3000", debug=True) \ No newline at end of file +app.run(port="3148", debug=True) \ No newline at end of file diff --git a/prefix.py b/prefix.py new file mode 100644 index 0000000..84db60a --- /dev/null +++ b/prefix.py @@ -0,0 +1,14 @@ +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()]