From f5244ee88b8b612bde0d4ccc87533293e1a34fd7 Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Fri, 19 Jul 2024 10:40:40 +0200 Subject: [PATCH] =?UTF-8?q?Fler=20utskrifter=20f=C3=B6r=20fels=C3=B6knings?= =?UTF-8?q?=C3=A4ndam=C3=A5l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/startservices.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/smartassist/src/startservices.py b/smartassist/src/startservices.py index 102f1fa..9ca79a0 100644 --- a/smartassist/src/startservices.py +++ b/smartassist/src/startservices.py @@ -2,6 +2,7 @@ import subprocess import os import yaml +import json from backend import run_flask import socket import urllib.parse @@ -40,12 +41,12 @@ def start_frontend(config): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: try: s.bind((hostname, port)) - print("No server is running on this host and port.") + print(f"No server is running on {parsed_url.netloc} —- starting up one.") # Start frontend (web server) as a separate process subprocess.Popen(["python", "-m", "http.server", str(port)]) except socket.error as e: if e.errno == 48: - print("Another server is already running on this host and port. Assumes it is a web server, will continue.") + print(f"A server is already running on {parsed_url.netloc} -— will use this.") else: raise # Unexpected error, re-raise it so we can see the traceback except Exception as e: @@ -56,16 +57,16 @@ def start_backend(config): parsed_url = urllib.parse.urlparse(config['backend']['url']) # hostname = parsed_url.netloc.split(':')[0] # Split by ':' and take the first part, i.e., 'localhost', IP, or domain name port = parsed_url.port # This is the server port - print(f"{port}") + # print(f"{port}") try: - run_flask(port = port) + run_flask(fport = port) except Exception as e: print(f"Failed to start backend: {e}") if __name__ == '__main__': conf = configure() # Read config from file and set up config dict - print(conf) - start_frontend(config=conf) # No need for this as the backend starts a web server on its own. + print(json.dumps(conf, indent=4)) + start_frontend(config=conf) start_backend(config=conf)