From 37d9e3780f8ec7227f26e0ec3f00cc431adbbb72 Mon Sep 17 00:00:00 2001 From: Sophie Schiller Date: Sun, 19 May 2024 15:11:57 +0200 Subject: [PATCH] gunicorn? --- README | 6 ++++++ app.py | 30 ++++++++++++++++-------------- gunicorn_config.py | 14 ++++++++++++++ requirements.txt | 2 +- wsgi.py | 9 --------- 5 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 gunicorn_config.py delete mode 100644 wsgi.py diff --git a/README b/README index 2b57e6b..72c6f8e 100644 --- a/README +++ b/README @@ -3,3 +3,9 @@ HTTP Triggered Sample Player Absolutely no access control. Horribly insecure. Only use in internal networks. + +can be started via: + +``` +gunicorn --config gunicorn_config.py app:app +``` diff --git a/app.py b/app.py index ae26827..b7da287 100644 --- a/app.py +++ b/app.py @@ -1,26 +1,28 @@ -from playsound import playsound -from flask import Flask -from flask import render_template -from markupsafe import escape from os import listdir from os.path import join + +from flask import Flask, render_template +from markupsafe import escape +from playsound import playsound + app = Flask(__name__) -samplefiles = listdir('samples') +samplefiles = listdir("samples") samples = [] for f in samplefiles: - if '.wav' in f: - samples.append(f.replace('.wav', '')) + if ".wav" in f: + samples.append(f.replace(".wav", "")) -@app.route('/') + +@app.route("/") def hello(): - return render_template('index.html', samples=samples) + return render_template("index.html", samples=samples) -@app.route('/play/') + +@app.route("/play/") def door(sample): if sample in samples: - playsound(join('samples', f'{sample}.wav')) - return f'

{escape(sample)}!

' + playsound(join("samples", f"{sample}.wav")) + return f"

{escape(sample)}!

" else: - return 'no such sample' - + return "no such sample" diff --git a/gunicorn_config.py b/gunicorn_config.py new file mode 100644 index 0000000..6d53bc5 --- /dev/null +++ b/gunicorn_config.py @@ -0,0 +1,14 @@ +import os + +workers = int(os.environ.get("GUNICORN_PROCESSES", "2")) + +threads = int(os.environ.get("GUNICORN_THREADS", "4")) + +# timeout = int(os.environ.get('GUNICORN_TIMEOUT', '120')) + +bind = os.environ.get("GUNICORN_BIND", "0.0.0.0:8080") + + +forwarded_allow_ips = "*" + +#secure_scheme_headers = {"X-Forwarded-Proto": "https"} diff --git a/requirements.txt b/requirements.txt index 2969b1e..773ecb8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ Flask +Gunicorn playsound -pygobject diff --git a/wsgi.py b/wsgi.py deleted file mode 100644 index dc985b6..0000000 --- a/wsgi.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/python3 -import sys -import logging -logging.basicConfig(stream=sys.stderr) -sys.path.insert(0,"/root/customer-account-automation/") - -from app import app as application -app = application -