speed_camera_detector / database /START_BACKEND.md
Rathesh07's picture
Uploaded files
30be4c2
|
Raw History Blame Contribute Delete
1.72 kB

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:

cd ..\backend

Or from the project root:

cd backend

2. Make sure DATABASE_URL is set:

# Windows PowerShell
$env:DATABASE_URL="postgresql+asyncpg://postgres:YOUR_PASSWORD@localhost:5432/navigation_app"

3. Start the server:

uvicorn main:app --reload --host 0.0.0.0 --port 8020

Full Command Sequence:

# 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:

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.