|
6 | 6 | # Function to run the FastAPI app |
7 | 7 | def run_fastapi(): |
8 | 8 | try: |
9 | | - # Assuming the FastAPI app is in app.py |
| 9 | + # Check if uvicorn is available in the environment |
10 | 10 | print("Starting FastAPI server...") |
11 | | - subprocess.run(["uvicorn", "src.chatbot.main:app", "--host", "0.0.0.0", "--port", "8000"]) |
| 11 | + process = subprocess.Popen( |
| 12 | + ["uvicorn", "src.chatbot.main:app", "--host", "0.0.0.0", "--port", "8000"], |
| 13 | + stdout=subprocess.PIPE, |
| 14 | + stderr=subprocess.PIPE, |
| 15 | + universal_newlines=True |
| 16 | + ) |
| 17 | + |
| 18 | + # Stream FastAPI output to the terminal |
| 19 | + for stdout_line in iter(process.stdout.readline, ""): |
| 20 | + print(stdout_line, end="") |
| 21 | + |
| 22 | + # Check if FastAPI process has completed |
| 23 | + process.stdout.close() |
| 24 | + process.wait() |
| 25 | + |
12 | 26 | except Exception as e: |
13 | 27 | print(f"Error running FastAPI: {e}") |
14 | 28 |
|
15 | | -# Function to update and run the React app |
| 29 | +# Function to run the React app |
16 | 30 | def run_react(): |
17 | 31 | try: |
18 | 32 | # Set working directory to the frontend React folder |
| 33 | + print("Starting React app...") |
19 | 34 | os.chdir('frontend-react') |
20 | 35 |
|
21 | | - # Install dependencies if needed |
22 | | - print("Installing npm dependencies...") |
| 36 | + # Install dependencies if needed (can be skipped if already installed) |
23 | 37 | subprocess.run(["npm", "install"]) |
24 | 38 |
|
25 | | - # Fix vulnerabilities and update deprecated options |
26 | | - print("Fixing vulnerabilities and updating dependencies...") |
27 | | - #subprocess.run(["npm", "audit", "fix"]) |
28 | | - #subprocess.run(["npm", "audit", "fix", "--force"]) |
29 | | - |
30 | | - # Start the React app using npm start |
31 | | - print("Starting React app...") |
| 39 | + # Run the React app using npm start |
32 | 40 | subprocess.run(["npm", "start"]) |
| 41 | + |
33 | 42 | except Exception as e: |
34 | 43 | print(f"Error running React app: {e}") |
35 | | - finally: |
36 | | - # Return to the original directory |
37 | | - os.chdir('..') |
38 | 44 |
|
39 | 45 | # Main function to run both FastAPI and React concurrently |
40 | 46 | def main(): |
|
0 commit comments