Web Socket server written in Node.js (using socket.io) for the MLP Vector Club's website
$ sudo npm install -g pm2
$ pnpm install
$ pnpm run build
$ cp .env.example .env # then fill in the values
$ pm2 start pm2.json
- Winterchilla's visitors are recognized by the
accesscookie, which is looked up in thesessionstable of the database (DB_NAME,mlpvc-rrunless set). - Luna's front end (Celestia) sends a one time token when it connects (
auth: { token }, from Luna'sPOST /users/me/socket-token), andLUNA_URLis where the server asks Luna who it belongs to (POST /internal/websocket/validate, authorized withWS_SERVER_KEY). WithoutLUNA_URLsuch sockets are guests. - The
originof every browser has to matchORIGIN_REGEX, e.g.^https://(next\.|old\.)?mlpvector\.club$for the apex (Celestia),next.(redirects to the apex) andold.(Winterchilla).
POST /notify with Authorization: Bearer <WS_SERVER_KEY> and {"user": "<id>"} makes the server send that user's open browsers the current unread count
(notif-cnt), which is what makes them look at their notifications again. Luna does this whenever a notification is sent or read (WS_SERVER_URL of Luna points
here, http://127.0.0.1:3672); nginx must not expose it (setup/nginx.conf).
- Image:
ghcr.io/mlp-vectorclub/muffins(tagssha-<sha7>), built fromdocker/Dockerfileon every push tomain(amd64 + arm64). Production sync: theDeployworkflow (manual, asks Argo CD to syncmuffins-prod). - Port
3672(HTTP + WebSocket, plain; TLS is terminated by the ingress). Health:GET /health(200 when the database answers, 503 otherwise). Both websocket and long-polling transports are used.POST /notify(BearerWS_SERVER_KEY) is called by Luna. - Environment, no
.envin the image:DB_HOST,DB_NAME,DB_USER,DB_PASS,WS_SERVER_KEY,ORIGIN_REGEX, optionalLUNA_URL(needed for Luna's one time tokens),PORT,HOST(0.0.0.0in the image). - Database access is read-only:
SELECTonusers,sessionsandnotifications. - No volumes. Outbound: Postgres, Luna (
LUNA_URL) andhttps://www.cloudflare.com/ips-v4|v6. - State is in memory only (connected sockets); run one replica, clients reconnect on their own.