Skip to content

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.

PropertyValue
Local base URLhttp://localhost:3000/api/v1
Production base URLhttps://api.myeasyguide.com/api/v1
Health checkGET /api/v1/health
Swagger UIhttp://localhost:3000/docs
OpenAPI JSONhttp://localhost:3000/docs.json
DatabasePostgreSQL, database myeasyguide_prod

Response shape ​

The API predates a single response envelope, so shapes differ by controller. Most endpoints return one of:

json
{ "message": "Data fetched successfully", "data": ... }
json
{ "activities": [...], "pagination": { "page": 1, "limit": 20, "total": 84, "totalPages": 5 } }
json
{ "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.

CookieSet byRead by
user_auth_tokenPOST /users/loginuserAuthMiddleware
auth_token + supplier_auth_tokenPOST /supplier/loginauthMiddleware / supplierAuthMiddleware
admin_auth_tokenPOST /admin/loginadminMiddleware

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 ​

MiddlewareAcceptsUsed for
userAuthMiddlewareuser_auth_token onlyTraveller routes: bookings, wishlist, reviews, checkout
supplierAuthMiddlewaresupplier_auth_token onlySupplier dashboard and payouts
adminMiddlewareadmin_auth_token onlyAdmin operations
authMiddlewareany of auth_token, author_auth_token, admin_auth_token, supplier_auth_tokenLegacy shared routes such as activity create/update

Pagination and filters ​

List endpoints generally accept:

ParamMeaning
page1-based page number
limitPage size (controller-specific maximum)
searchTitle/description search
categoryCategory slug or id
city or locationLocation slug; matches the denormalised locationAncestors array
minPrice, maxPricePrice bounds
statusAdmin-only activity status filter
featured, promotedAdmin-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 = true and status = APPROVED.
  • The public activity list and popularity endpoint filter on published = true only. Treat APPROVED as 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:

EndpointProtection
POST /inquiryTurnstile action trip_inquiry
POST /reportTurnstile action problem_report
POST /supplier/public/:id/contactTurnstile action supplier_contact
POST /newsletter/subscribeRate 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.

Built with VitePress