React app bootstrapped with Create React App, using MUI and Axios. Points to the backend API for data.
- React 18, TypeScript
- CRA (react-scripts)
- MUI (@mui/material)
- Axios
- ESLint
- Node.js 18+
- npm 9+
- Install dependencies:
npm ci
- Start the dev server:
Runs on
npm start
http://localhost:3000. A development proxy is configured tohttp://localhost:3001inpackage.json.
High-level overview of principal files/directories:
frontend/
├─ src/
│ ├─ index.tsx # App bootstrap
│ ├─ App.tsx # Root component
│ ├─ pages/ # Route pages
│ ├─ components/ # UI components
│ ├─ services/ # API client and services
│ └─ types/ # Shared TS types
├─ public/ # Static assets and index.html template
├─ build/ # Production build output
├─ .env.example # Environment variables template
└─ tsconfig.json
npm start: Start dev servernpm run build: Production build tobuild/npm test: Run tests (interactive)npm run lint: Lintnpm run lint:fix: Lint and fix
The API base URL defaults to http://localhost:3001/api in src/services/api.ts:
export const API_BASE_URL = "http://localhost:3001/api";For production deployments, update this to your backend URL (e.g. https://api.example.com/api) or refactor it to read from an environment variable at build time.
Example using CRA runtime via env at build (needs code change):
- Add
REACT_APP_API_BASE_URL=https://api.example.com/apito your build environment - Read it in code:
process.env.REACT_APP_API_BASE_URL
Create a .env file (or .env.production for builds) using this template:
# Frontend environment variables (Create React App)
# NOTE: Variables must be prefixed with REACT_APP_
# Base URL of the backend API including the /api prefix
REACT_APP_API_BASE_URL=http://localhost:3001/api
# Example: build-time environment indicator (optional)
REACT_APP_ENV=developmentnpm run buildOutputs optimized static assets to build/.
- Build the app locally:
npm run build
- Create an S3 bucket with static website hosting enabled.
- Upload the contents of the
build/folder to the bucket (drag-and-drop or AWS CLI). - Set bucket policy/public access appropriately or serve via CloudFront for HTTPS and caching.
- Ensure your backend CORS allows the S3/CloudFront domain.
- Any static server can serve the
build/directory - Example with
serve(for quick checks only):npx serve -s build -l 3000
- With NGINX, point a server block to the
build/directory and route API requests to the backend domain
- Backend must set
CORS_ORIGINto the deployed frontend origin - Frontend must call the correct API URL (update
API_BASE_URLor env)
- API calls fail in production → Check
API_BASE_URLand CORS on backend - Dev works but prod fails → Confirm env vars are available at build time and the built JS contains the correct URL
- SPA 404 on refresh → Ensure host rewrites all routes to
index.html