message-server/README.md

37 lines
1.4 KiB
Markdown

# Message server
## Running
### Starting servers
Server ID (`SERVER_ID`) and remote servers (`SERVERS`) are provided as environment variables along with shared auth key (`AUTH_KEY`).
#### Server 1
```bash
SERVER_ID=1 SERVERS="2:localhost:4001" PORT=4000 mix run --no-halt
```
#### Server 2
```bash
SERVER_ID=2 SERVERS="1:localhost:4000" PORT=4001 mix run --no-halt
```
### Sending messages
#### From Server 1
```curl
curl -X POST http://localhost:4000/api/messages -H "Content-Type: application/json" -d '{"from": "1-bender", "to": "1-zoidberg", "message": "Dreams are where elves and gnomes live!"}'
```
```curl
curl -X POST http://localhost:4000/api/messages -H "Content-Type: application/json" -d '{"from": "1-bender", "to": "2-nibbler", "message": "Bite my shiny metal ass!"}'
```
#### From Server 2
```curl
curl -X POST http://localhost:4001/api/messages -H "Content-Type: application/json" -d '{"from": "2-nibbler", "to": "1-bender", "message": "I am Nibbler, agent of the Nibblonian fleet."}'
```
## Security
This application uses a shared auth key (`AUTH_KEY`) to authenticate requests between servers. The key is provided as an environment variable and must be the same on all servers.
### Next steps
HTTPS with client certificates should be implemented to ensure secure communication between servers and prevent unauthorized access and possible man-in-the-middle attacks.