Deployment · By Rivtor · Updated
Deploy Vite, Express and PostgreSQL together
Deploy Vite as built static assets, Express as a separately started Node.js API and PostgreSQL as the persistent data service. Decide whether requests use one public origin or two, then build the frontend with the appropriate API address.
See the Rivtor deployment workflow →
Decide who serves the frontend
Two common designs are a static host plus a public Express API, or Express serving both its API and the built frontend. Choose deliberately: a development proxy in Vite does not automatically exist after the production build.
For separate services, keep web/package.json and api/package.json independently installable and give the API its own start script. For a combined service, ensure the built assets are copied into the runtime image and API routes are registered before a frontend fallback.
Replace development-only networking
// Browser-side configuration for a Vite build:
const base = import.meta.env.VITE_API_URL;
const response = await fetch(new URL('/api/health', base));
if (!response.ok) throw new Error('API unavailable');
This illustrative request uses an absolute public API URL. For a deliberately configured same-origin deployment, a relative /api/health path can be appropriate instead. Choose one contract; do not let a missing variable silently send requests to localhost.
| Local assumption | Production replacement |
|---|---|
| Vite dev proxy | Explicit public API URL or a configured production proxy |
| Local .env file | Supported host environment configuration |
| Local database | Server-only DATABASE_URL |
| Development process | Built assets and a production Node entrypoint |
Keep the database behind Express
Use a bounded pg or ORM pool in the API process. Parameterize queries and run committed migrations through the release workflow. Never put database credentials into VITE_ variables: those values can be exposed in the browser bundle.
Rivtor documents Vite static output, Express detection and service URL wiring. Inspect the detected service configuration rather than assuming the development proxy will be reproduced.
Exercise direct navigation and API calls
Refresh a nested frontend page and inspect whether the static host’s fallback matches the application router. Verify that an unknown API path returns an API error rather than index.html with a 200 status. Create and read a synthetic record, restart Express and confirm persistence. If requests fail only in the browser, inspect the actual origin and CORS response before changing PostgreSQL settings.