-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
27 lines (24 loc) · 1007 Bytes
/
Copy pathrun.py
File metadata and controls
27 lines (24 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import uvicorn
import os
import tool
import platform
if __name__ == "__main__":
# run flag
while True:
choose_mode = input("choose run mode (0: dev, 1: qa, 2: prod): ").strip()
run_mode_mapping = {"0": "dev", "1": "qa", "2": "prod"}
run_mode = run_mode_mapping.get(choose_mode, None)
if run_mode is not None:
print(f"Selected run mode: {run_mode}")
os.system("cls" if platform.system() == "Windows" else "clear")
break
else:
print("Invalid input. Please enter 0, 1, or 2.")
# read server config file
uvicorn_config_toml = tool.read_toml_file("./_setting/ServerSetting.toml")
uvicorn_config: dict = uvicorn_config_toml.get(run_mode, {})
headers_tuple_list = tool.transfer_dict_to_tuple_list(uvicorn_config.get("headers", {}))
uvicorn_config.pop("headers", None)
uvicorn_config["headers"] = headers_tuple_list
# prepare uvicorn.run parameters
uvicorn.run(**uvicorn_config)