REST API api
The core backend and system of business logic — a Node.js/Express service over MongoDB that every other component depends on.
macaroni-kid-2.api (v1.5.8)express-restify-mongoose & express-async-errorsmongoose-deep-populatejsonwebtoken, bcryptjs, speakeasy (2FA/TOTP)ecosystem.config.js)3000 (mapped to 8080 in the Docker setup)/api/v1/Structure
The app boots from app.js → bin/www. Middleware is registered around the router (middleware/), routes are wired in routes/, and request handling lives in controllers/ backed by Mongoose models/. Cross-cutting concerns (email, search, third-party APIs) live in services/.
Notable services
| Service | Purpose |
|---|---|
services/search.js | OpenSearch indexing & queries (Article / Business / Event) |
services/sendGrid.js, services/email.js | Transactional email (SendGrid, SES via nodemailer) |
services/ongage.js | Ongage ESP integration |
services/monday.js | Monday.com integration |
services/connectionMonitor.js | Monitors data-store connections (used by the worker) |
Notable endpoints
| Route | Purpose |
|---|---|
/api/v1/statistic/trackView | Records a public pageview into TownViewCount |
/api/v1/statistic/townViewCount | Aggregated pageview reporting (admin dashboards) |
/api/v1/statistic/townRank, …/newsletterTotalByTown | Town ranking & newsletter totals |
/debug-sentry | Sentry test endpoint |
Observability
Sentry is initialized in instrument.js (loaded before the app) with @sentry/node and profiling. Process-level unhandledRejection and uncaughtException handlers log diagnostic detail. Winston and Morgan provide application and request logging.
Deployment
Production runs under PM2 in cluster mode (4 instances) via ecosystem.config.js, which also defines a deploy target: user root on host 198.74.62.36 (Linode), pulling origin/master into /var/www/api, then npm install && pm2 startOrRestart. A Dockerfile (Node 18) is provided for containerized runs; cron/queue work runs in a separate worker process.
npm run start:worker / Dockerfile.worker). The two share one codebase but run as separate processes.