prefix middleware

master
km0 2 years ago
parent 321f255123
commit 1a36a7cdc8

@ -8,8 +8,31 @@ import json
from pathlib import Path
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()]
app = Flask(__name__)
# register the middleware to prefix all the requests with our base_url
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/soupboat/workbook')
def create_instrument(name, description, params, sockets, panel):
slug = secure_filename(name)
os.mkdir(f'instruments/{slug}')
@ -124,4 +147,4 @@ def patch(instrument, name):
app.run(port=3000, debug=True)
app.run(port=3146, debug=True)
Loading…
Cancel
Save