Fler utskrifter för felsökningsändamål
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
|
import json
|
||||||
from backend import run_flask
|
from backend import run_flask
|
||||||
import socket
|
import socket
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
@@ -40,12 +41,12 @@ def start_frontend(config):
|
|||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
try:
|
try:
|
||||||
s.bind((hostname, port))
|
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
|
# Start frontend (web server) as a separate process
|
||||||
subprocess.Popen(["python", "-m", "http.server", str(port)])
|
subprocess.Popen(["python", "-m", "http.server", str(port)])
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
if e.errno == 48:
|
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:
|
else:
|
||||||
raise # Unexpected error, re-raise it so we can see the traceback
|
raise # Unexpected error, re-raise it so we can see the traceback
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -56,16 +57,16 @@ def start_backend(config):
|
|||||||
parsed_url = urllib.parse.urlparse(config['backend']['url'])
|
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
|
# 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
|
port = parsed_url.port # This is the server port
|
||||||
print(f"{port}")
|
# print(f"{port}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run_flask(port = port)
|
run_flask(fport = port)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to start backend: {e}")
|
print(f"Failed to start backend: {e}")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
conf = configure() # Read config from file and set up config dict
|
conf = configure() # Read config from file and set up config dict
|
||||||
print(conf)
|
print(json.dumps(conf, indent=4))
|
||||||
start_frontend(config=conf) # No need for this as the backend starts a web server on its own.
|
start_frontend(config=conf)
|
||||||
start_backend(config=conf)
|
start_backend(config=conf)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user