Spaces:
Runtime error
Runtime error
File size: 1,723 Bytes
30be4c2 | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | # How to Start the FastAPI Backend
## Important: Run from the correct directory!
The FastAPI backend (`main.py`) is in the `backend` folder, not the `database` folder.
## Steps:
### 1. Navigate to the backend directory:
```bash
cd ..\backend
```
Or from the project root:
```bash
cd backend
```
### 2. Make sure DATABASE_URL is set:
```powershell
# Windows PowerShell
$env:DATABASE_URL="postgresql+asyncpg://postgres:YOUR_PASSWORD@localhost:5432/navigation_app"
```
### 3. Start the server:
```bash
uvicorn main:app --reload --host 0.0.0.0 --port 8020
```
## Full Command Sequence:
```powershell
# Set database URL (if not already set)
$env:DATABASE_URL="postgresql+asyncpg://postgres:YOUR_PASSWORD@localhost:5432/navigation_app"
# Navigate to backend
cd ..\backend
# Start server
uvicorn main:app --reload --host 0.0.0.0 --port 8020
```
## Verify it's working:
Once started, you should see:
```
INFO: Uvicorn running on http://0.0.0.0:8020 (Press CTRL+C to quit)
INFO: Started reloader process [...]
INFO: Started server process [...]
INFO: Waiting for application startup.
β Database initialized
INFO: Application startup complete.
```
## Test the API:
Open in browser or use curl:
- Health check: http://localhost:8020/health
- API docs: http://localhost:8020/docs
- Cameras: http://localhost:8020/api/cameras/nearby?latitude=13.0827&longitude=80.2707&radius_meters=5000
## Troubleshooting:
### "Could not import module 'main'"
- You're in the wrong directory. Make sure you're in the `backend` folder.
### "DATABASE_URL is not set"
- Set the environment variable before starting the server.
### "password authentication failed"
- Check your PostgreSQL password in DATABASE_URL.
|