Frontend API Client
axios instance, interceptors, and endpoint usage.
axios instance
src/api/axios.js creates a single axios instance with baseURL = process.env.REACT_APP_API_BASE_URL (default http://localhost:3001/api).
Request interceptor
Attaches Authorization: Bearer <token> from localStorage.access_token and sets cache-busting headers (no-cache, Pragma, Expires).
Response interceptor
On 401 (excluding /login, /register, /refresh), calls POST /api/refresh with the stored refresh_token; on success retries the original request; on failure clears tokens and redirects to /login or /admin/login based on the current path.
Superadmin axios
superAdmin/SuperAdmin.js creates a separate bare axios instance (no interceptors) for /superadmin/* endpoints, using its own superadmin_token in localStorage.
Endpoint map (frontend → backend)
| Feature | Method | Path |
|---|---|---|
| Login | POST | /login |
| Register | POST | /register |
| Logout | POST | /logout |
| Refresh | POST | /refresh |
| Profile | GET | /profile |
| Profile edit | PUT (multipart) | /profile |
| User roles | GET | /users/:id/roles |
| Videos | GET | /youtube/videos |
| Articles | GET | /articles/all, /articles/:id |
| Forum categories | GET | /forum/categories |
| Forum threads | GET/POST | /forum/threads, /forum/threads/:id |
| Thread reply | POST (multipart) | /forum/threads/:id/reply |
| Thread like | POST | /forum/threads/:id/like |
| Reminders | GET/POST | /pengingat, /pengingat/obat |
| Reminder update/delete | PUT/DELETE | /pengingat/:id |
| Nearby faskes | GET | /faskes/nearby?lat=&lng= |
| Faskes location | GET | /faskes/location?lat=&lng= |
| Faskes search | GET | /faskes/search?keyword= |
| Doctors | GET | /dokter |
| Communities | GET | /komunitas |
| Push subscribe | POST | /push/subscribe |
| User log | POST | /log/user-log |
| Admin log | POST | /log/admin-log |
| Superadmin login | POST | /superadmin/login |
| Superadmin query | POST | /superadmin/query |
| Superadmin tables | GET | /superadmin/tables, /superadmin/tables/:name |
| Superadmin export | GET/POST | /superadmin/tables/:name/export, /superadmin/query/export |
Base path
All paths are relative to /api. So POST /login means POST {API_BASE_URL}/login.
Activity logging
src/hooks/useActivity.js (useActivityLogger()) runs across nearly every page. It calls POST /log/user-log (users) or POST /log/admin-log (admins) with event_type, event_name, screen_name, activity description, session_id, and user IP (fetched from api.ipify.org, cached 1 hour in localStorage). Logging is fire-and-forget — errors are swallowed.
Image URL helper
src/utils/image.js — getImageUrl() prefixes relative paths with REACT_APP_MEDIA_BASE and strips double slashes. Used for all backend-served media.