fix run webapp

This commit is contained in:
ALIHAN DIKEL
2025-03-10 15:42:37 +03:00
parent dba6106b63
commit 7f2c20cb07

View File

@@ -4,28 +4,31 @@ from dotenv import load_dotenv
import uvicorn
# Load environment variables from .env file
load_dotenv("env")
# Get variables with defaults
HOST = os.getenv("HOST", "0.0.0.0")
PORT = int(os.getenv("PORT", "8000"))
RELOAD = os.getenv("RELOAD", "True").lower() == "true"
APP_MODULE = os.getenv("APP_MODULE", "main:app")
WORKING_DIR = os.getenv("WORKING_DIR", os.getcwd())
load_dotenv()
def main():
"""Run the uvicorn server directly using the Python API"""
# Change to the specified working directory
os.chdir(WORKING_DIR)
# Set working directory to src (the crucial part)
src_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src")
os.chdir(src_dir)
# Add the working directory to Python path if needed
if WORKING_DIR not in sys.path:
sys.path.insert(0, WORKING_DIR)
# Add src directory to Python path
if src_dir not in sys.path:
sys.path.insert(0, src_dir)
uvicorn.run(APP_MODULE, host=HOST, port=PORT, reload=RELOAD)
# Get variables with defaults
host = os.getenv("HOST", "0.0.0.0")
port = int(os.getenv("PORT", "9999"))
reload = os.getenv("RELOAD", "True").lower() == "true"
# Run server
uvicorn.run(
"main:app", # Now main.py will be found in src directory
host=host,
port=port,
reload=reload
)
if __name__ == "__main__":
main()
main()