refactor: server.py

This commit is contained in:
Kevin Restaino
2024-01-08 23:48:46 -05:00
parent d703c6bf05
commit 651ed3f516
3 changed files with 14 additions and 13 deletions
+2 -2
View File
@@ -10,8 +10,8 @@ COPY . .
# Install any needed packages specified in requirements.txt # Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# Expose port 3333 for the Flask app # Expose port 5000 for the Flask app
EXPOSE 3333 EXPOSE 5000
# Set the entrypoint to Python # Set the entrypoint to Python
ENTRYPOINT ["python", "sptnr.py"] ENTRYPOINT ["python", "sptnr.py"]
+7 -6
View File
@@ -9,6 +9,12 @@ services:
# Uncomment the next line to build the Docker image locally # Uncomment the next line to build the Docker image locally
# build: . # build: .
# Uncomment the next line to run the script
# entrypoint: ["python", "sptnr.py"]
# Uncomment the next line to start the web server
# entrypoint: ["gunicorn", "-b", "0.0.0.0:5000", "web_server:sptnr_web_server"]
environment: environment:
- NAV_BASE_URL=your_navidrome_server_url - NAV_BASE_URL=your_navidrome_server_url
- NAV_USER=your_navidrome_username - NAV_USER=your_navidrome_username
@@ -20,9 +26,4 @@ services:
volumes: volumes:
- ./data:/usr/src/app/data - ./data:/usr/src/app/data
ports: ports:
- "3333:3333" - "3333:5000"
# Uncomment the next line to just run the script
# entrypoint: ["python", "sptnr.py"]
# Uncomment the next line to start the web server
# entrypoint: ["python", "web_server.py"]
+5 -5
View File
@@ -7,7 +7,7 @@ import functools
load_dotenv() load_dotenv()
sptnr_web_server = Flask(__name__) sptnr = Flask(__name__)
WEB_API_KEY = os.getenv("WEB_API_KEY") WEB_API_KEY = os.getenv("WEB_API_KEY")
ENABLE_WEB_API_KEY = os.getenv("ENABLE_WEB_API_KEY", "True") == "True" ENABLE_WEB_API_KEY = os.getenv("ENABLE_WEB_API_KEY", "True") == "True"
LOG_DIR = "data/logs" LOG_DIR = "data/logs"
@@ -27,7 +27,7 @@ def run_script(cmd):
subprocess.run(cmd) subprocess.run(cmd)
@sptnr_web_server.route("/process", methods=["GET", "POST"]) @sptnr.route("/process", methods=["GET", "POST"])
@api_key_required @api_key_required
def process_request(): def process_request():
cmd = ["python3", "sptnr.py"] cmd = ["python3", "sptnr.py"]
@@ -54,7 +54,7 @@ def process_request():
return jsonify({"message": "Processing started"}) return jsonify({"message": "Processing started"})
@sptnr_web_server.route("/logs") @sptnr.route("/logs")
@api_key_required @api_key_required
def list_logs(): def list_logs():
try: try:
@@ -67,7 +67,7 @@ def list_logs():
return f"An error occurred: {e}", 500 return f"An error occurred: {e}", 500
@sptnr_web_server.route("/logs/<filename>") @sptnr.route("/logs/<filename>")
@api_key_required @api_key_required
def view_log(filename): def view_log(filename):
try: try:
@@ -86,4 +86,4 @@ def view_log(filename):
if __name__ == "__main__": if __name__ == "__main__":
sptnr_web_server.run(debug=False, host="0.0.0.0", port=3333) sptnr.run(debug=False, host="0.0.0.0", port=3333)