diff options
Diffstat (limited to 'backend/main.py')
-rw-r--r-- | backend/main.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/backend/main.py b/backend/main.py new file mode 100644 index 0000000..1678f24 --- /dev/null +++ b/backend/main.py @@ -0,0 +1,34 @@ +import HTTP +import json + +def playout(filename): + return ["", [('Content-Type','text/html'), ('X-Accel-Redirect', filename)], None] + +def route(path, env, session, post): + if path[0] == "8cabc1fce52bcb565ae203267ce7e73f69a9272e": + return playout("interface/listing.htm") + if path[0] == "test": + return playout("interface/listing.htm") + + # Default path + return ["", [("Content-type", "text/html")], "404 None such"] + +def handle_request(env, response): + path = env.get('PATH_INFO', '').lstrip('/').split('/') + post = {} + headers = [] + + # Read POST data + try: + content_length = int(env.get('CONTENT_LENGTH', '0')) + post_raw = env["wsgi.input"].read(content_length).decode('utf-8') + if env.get('CONTENT_TYPE', '') == "multipart/form-data": + post = HTTP.formdata(post_raw) + except ValueError as e: + post = None + + # Route request + data, addtl_headers, code = route(path, env, session, post) + headers.extend(addtl_headers) + response(code if code else "200 OK", headers) + return [bytes(data)] |