-
Notifications
You must be signed in to change notification settings - Fork 1
Description
app = FastAPI()
# Allow all origins
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # You can replace this with specific origins if needed
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def howdy():
return {"Howdy": "World"}
app.mount("/static", StaticFiles(directory=os.path.join(parent_dir,"static")), name="static")
def run_server():
global server
logger.debug(f"Starting server on {SERVER_HOST}:{SERVER_PORT}")
try:
server =ServerThread(app,host=SERVER_HOST,port=SERVER_PORT)
except Exception as e:
logger.exception(f"Exception in server thread!: {e}")
def main():
server_thread = Thread(name="Server", target=run_server)
server_thread.daemon = True
server_thread.start()
# run_thread(validate_or_remove_license)
# run_thread(run_cache_cleanup_later)
# Ensure the webserver is up & running by polling it
waits = 0
while waits < 10:
try:
print(f"http://{server.host}:{server.port}")
response = requests.get(f"http://{server.host}:{server.port}/")
response.raise_for_status()
except requests.RequestException as e:
logger.warning(f"Waiting for main window: {e}")
sleep(0.1 * waits)
waits += 1
else:
break
else:
logger.critical("Webserver did not start properly!")
sys.exit(2)
http://::1:24643
2023-12-14T18:28:43 WARNING Waiting for main window: Failed to parse: http://::1:24643/
http://::1:24643
2023-12-14T18:28:43 WARNING Waiting for main window: Failed to parse: http://::1:24643/
http://::1:24643
2023-12-14T18:28:43 WARNING Waiting for main window: Failed to parse: http://::1:24643/
http://::1:24643
2023-12-14T18:28:44 WARNING Waiting for main window: Failed to parse: http://::1:24643/
http://::1:24643
2023-12-14T18:28:44 WARNING Waiting for main window: Failed to parse: http://::1:24643/
http://::1:24643
2023-12-14T18:28:44 WARNING Waiting for main window: Failed to parse: http://::1:24643/
http://::1:24643
2023-12-14T18:28:45 WARNING Waiting for main window: Failed to parse: http://::1:24643/
http://::1:24643
2023-12-14T18:28:45 WARNING Waiting for main window: Failed to parse: http://::1:24643/
http://::1:24643
2023-12-14T18:28:46 WARNING Waiting for main window: Failed to parse: http://::1:24643/
http://::1:24643
2023-12-14T18:28:47 WARNING Waiting for main window: Failed to parse: http://::1:24643/
2023-12-14T18:28:48 CRITICAL Webserver did not start properly!