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)