Skip to content

dfons007/FastAPIReact

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Setup

This guide shows how to run the FastAPI backend and the React (React Router + Vite) frontend.

Prerequisites

  • Python: 3.11+ recommended
  • Node.js: 18+ (20+ recommended) and npm
  • PostgreSQL: reachable instance (local or remote)

Environment

Set environment variables for the backend (defaults shown). Create a .env file or set in your shell:

DB_USER=postgres
DB_PASSWORD=your_password_here
DB_HOST=localhost
DB_PORT=5432
DB_NAME=postgres
DB_SCHEMA=local

Note: The code reads env vars directly via os.getenv. If you want .env auto-loading, add from dotenv import load_dotenv; load_dotenv() early in config.py.

Database Preparation

  1. Ensure the database exists and is reachable.
  2. Create the schema if it does not exist:
CREATE SCHEMA IF NOT EXISTS local;
  1. Create the table used by the app (if not using migrations):
CREATE TABLE IF NOT EXISTS local.local_testing (
  id integer PRIMARY KEY,
  value integer NULL
);

Backend (FastAPI)

  1. Create and activate a virtual environment:
python -m venv .venv
# Windows PowerShell
. .venv/Scripts/Activate.ps1
# macOS/Linux
source .venv/bin/activate
  1. Change into the backend directory and install dependencies:
cd backend-proj
pip install -r requirements.txt
  1. Run the server (default on http://127.0.0.1:8000):
uvicorn main:app --reload
  1. API Endpoints:
  • GET /grabTableRecords
  • POST /insertTableRecord
  • PUT /updateTableRecord
  • DELETE /deleteTableRecord/{id}

Frontend (React Router + Vite)

From the ui-proj directory:

cd ui-proj
npm install

Development (runs Vite dev server, typically http://localhost:5173):

npm run dev

Production build and serve SSR output:

npm run build
npm start

CORS

The backend allows origins http://localhost:5173 and http://localhost:3000. If your frontend runs elsewhere, update origins in backend-proj/main.py accordingly.

Common Troubleshooting

  • Postgres auth errors: verify DB_* variables and that the local schema exists.
  • Missing table: run the SQL in Database Preparation, or add SQLAlchemy migrations.
  • Port conflicts: change dev server ports (vite or uvicorn --port) and update origins.

About

Quick project using FastAPI + React

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published