montana/Russian/Site/messenger-backend/README.md
2026-05-18 18:05:32 +03:00

48 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Montana Messenger Relay
Federated relay backend for Montana Messenger (`montana.quest/messenger`).
## Stack
- Flask 3 + gunicorn
- PostgreSQL (table: accounts, sessions, messages)
- PyNaCl for ed25519 signature verify
- Listens on 127.0.0.1:5010 (proxied by nginx at /messenger/api/)
## Setup (on montana-moscow)
```bash
# 1. PostgreSQL
sudo -u postgres createuser -P montana
sudo -u postgres createdb -O montana montana_messenger
sudo -u postgres psql montana_messenger < /opt/app/messenger/schema.sql
# 2. Virtualenv
cd /opt/app/messenger
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
# 3. .env
cp .env.example .env # отредактировать DSN с реальным паролем
# 4. systemd
sudo cp montana-messenger.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now montana-messenger
sudo systemctl status montana-messenger
# 5. nginx
sudo cat nginx-snippet.conf
# скопировать содержимое в /etc/nginx/sites-available/montana_quest перед "location /"
sudo nginx -t && sudo systemctl reload nginx
```
## API
- `POST /api/auth/challenge` body `{accountId}``{challengeId, challenge, expiresAt}`
- `POST /api/auth/verify` body `{accountId, challengeId, signature}``{sessionToken, accountId, expiresAt}`
- `POST /api/msg/send` body `{recipient, ciphertext, nonce}` (Bearer) → `{msgId, createdAt}`
- `GET /api/msg/inbox?since=<ms>` (Bearer) → `{messages: [...]}`
- `GET /api/msg/contacts` (Bearer) → `{contacts: [...]}`
- `POST /api/msg/read` body `{msgIds}` (Bearer) → `{ok}`
- `GET /api/health` → liveness