Hallo Stroke

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)

FeatureMethodPath
LoginPOST/login
RegisterPOST/register
LogoutPOST/logout
RefreshPOST/refresh
ProfileGET/profile
Profile editPUT (multipart)/profile
User rolesGET/users/:id/roles
VideosGET/youtube/videos
ArticlesGET/articles/all, /articles/:id
Forum categoriesGET/forum/categories
Forum threadsGET/POST/forum/threads, /forum/threads/:id
Thread replyPOST (multipart)/forum/threads/:id/reply
Thread likePOST/forum/threads/:id/like
RemindersGET/POST/pengingat, /pengingat/obat
Reminder update/deletePUT/DELETE/pengingat/:id
Nearby faskesGET/faskes/nearby?lat=&lng=
Faskes locationGET/faskes/location?lat=&lng=
Faskes searchGET/faskes/search?keyword=
DoctorsGET/dokter
CommunitiesGET/komunitas
Push subscribePOST/push/subscribe
User logPOST/log/user-log
Admin logPOST/log/admin-log
Superadmin loginPOST/superadmin/login
Superadmin queryPOST/superadmin/query
Superadmin tablesGET/superadmin/tables, /superadmin/tables/:name
Superadmin exportGET/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.jsgetImageUrl() prefixes relative paths with REACT_APP_MEDIA_BASE and strips double slashes. Used for all backend-served media.

On this page