Skip to content

Deployment · By Rivtor · Updated

Deploy React, FastAPI and PostgreSQL with clear service boundaries

Build a React frontend to static assets, run FastAPI as a separate API service and keep PostgreSQL accessible only to server code. Configure the frontend’s public API URL during its build and verify CORS, browser requests and persistence after release.

See the Rivtor deployment workflow →

Give each service an independently usable root

A practical repository can contain frontend/package.json and api/requirements.txt, with FastAPI source and migration history inside api. React is a UI library; the frontend build tool determines output files and public environment-variable conventions. This example assumes Vite rather than treating every React project alike.

ServiceProduction inputDurable state
React/ViteBuilt dist directoryNone in the browser bundle
FastAPIASGI application and dependenciesUses PostgreSQL
PostgreSQLReviewed schema and application recordsManaged separately from the API process

Do not place the database connection string in frontend configuration. A static site cannot safely hold a secret even if the variable name does not contain the word public.

Set the API URL before building

With Vite, VITE_API_URL is public build input. For example, a frontend can call a deliberately configured public API endpoint:

const api = import.meta.env.VITE_API_URL;
const response = await fetch(new URL('/health', api));
if (!response.ok) throw new Error('API health request failed');

The origin must be a URL the visitor’s browser can reach. A private container hostname can be used by server-side services but not by the public browser. Changing an already-built bundle usually requires a new frontend build.

Configure origins and database access separately

Allow the actual frontend origin in FastAPI’s CORS settings when the browser calls another origin. Configure credentials only if the application needs them, with explicit allowed origins. CORS is not a database-access control or a replacement for API authorization.

Review Rivtor framework wiring, then apply the application’s reviewed migrations. Keep DATABASE_URL in the API environment and select a compatible driver.

Verify the complete path

Open a nested frontend route directly, call the API in browser developer tools and create a disposable record. Restart the API and confirm the record persists. An API health result alone does not demonstrate that the browser has the correct URL or that a production schema exists. Keep these observations separate when diagnosing the release.

References