API Overview
The Express API is the commerce backend for MyEasyGuide. It owns activities, departures, bookings, payments, suppliers, payouts, reviews, inquiries and the catalog that activities reference.
| Property | Value |
|---|---|
| Local base URL | http://localhost:3000/api/v1 |
| Production base URL | https://api.myeasyguide.com/api/v1 |
| Health check | GET /api/v1/health |
| Swagger UI | http://localhost:3000/docs |
| OpenAPI JSON | http://localhost:3000/docs.json |
| Database | PostgreSQL, database myeasyguide_prod |
Response shape
The API predates a single response envelope, so shapes differ by controller. Most endpoints return one of:
{ "message": "Data fetched successfully", "data": ... }{ "activities": [...], "pagination": { "page": 1, "limit": 20, "total": 84, "totalPages": 5 } }{ "message": "Created" }Check the endpoint page or /docs for the exact shape. Errors consistently use { "message": "..." }, sometimes with errors (Zod issues) or available (payout guard).
Authentication
Authentication is cookie-based for browser clients and bearer-token-friendly for other clients. Logging in sets an httpOnly cookie; the login response also returns the raw JWT.
| Cookie | Set by | Read by |
|---|---|---|
user_auth_token | POST /users/login | userAuthMiddleware |
auth_token + supplier_auth_token | POST /supplier/login | authMiddleware / supplierAuthMiddleware |
admin_auth_token | POST /admin/login | adminMiddleware |
JWT_EXPIRY is in seconds (default 7 days). COOKIE_AGE is in milliseconds because it is passed to the cookie maxAge. In production, cookies use SameSite=None, Secure, and the domain from COOKIE_DOMAIN so they can be shared across subdomains.
See Auth for the full flow.
Middleware
| Middleware | Accepts | Used for |
|---|---|---|
userAuthMiddleware | user_auth_token only | Traveller routes: bookings, wishlist, reviews, checkout |
supplierAuthMiddleware | supplier_auth_token only | Supplier dashboard and payouts |
adminMiddleware | admin_auth_token only | Admin operations |
authMiddleware | any of auth_token, author_auth_token, admin_auth_token, supplier_auth_token | Legacy shared routes such as activity create/update |
Pagination and filters
List endpoints generally accept:
| Param | Meaning |
|---|---|
page | 1-based page number |
limit | Page size (controller-specific maximum) |
search | Title/description search |
category | Category slug or id |
city or location | Location slug; matches the denormalised locationAncestors array |
minPrice, maxPrice | Price bounds |
status | Admin-only activity status filter |
featured, promoted | Admin-only activity flags |
A location filter matches the location itself and all descendants, because activities store a denormalised ancestor list and the API queries it with a GIN index.
Visibility rules
There are two separate columns: published and status.
- Public detail, path lookup, booking, inquiry and public supplier profile require
published = trueandstatus = APPROVED. - The public activity list and popularity endpoint filter on
published = trueonly. TreatAPPROVEDas the stricter invariant; do not assume every listed activity is approved. - An activity owner or an admin may read an unpublished activity by id.
- A suspended supplier cannot log in, cannot use supplier routes, and their public profile/activities are hidden.
Public write endpoints
Four endpoints create side effects without a login:
| Endpoint | Protection |
|---|---|
POST /inquiry | Turnstile action trip_inquiry |
POST /report | Turnstile action problem_report |
POST /supplier/public/:id/contact | Turnstile action supplier_contact |
POST /newsletter/subscribe | Rate limiter only |
Turnstile verification requires both TURNSTILE_SECRET and a matching hostname in TURNSTILE_HOSTNAMES. Local development fails closed, so set a localhost entry and a test secret/key pair.
Rate limiting and CORS
express-rate-limit is applied to the whole /api/v1 router. CORS allows credentials from the origins in FRONTEND_ORIGINS, plus the deployed myeasyguide.com origins. Browser requests therefore need credentials: "include".
Uploads
POST /upload accepts multipart files. Uploads are converted to WebP with Sharp and stored either in Cloudflare Images or under public/uploads for the local endpoints. See Catalog & Media.