diff --git a/README.md b/README.md index a93592c..456d0dc 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,23 @@ environment: - DATABASE_URL=sqlite:///./drugs.db ``` +## MQTT + +The system includes an MQTT broker (Mosquitto) with WebSocket support: + +- **MQTT**: `localhost:1883` +- **WebSocket**: `localhost:9001` or `/mqtt` via nginx + +To create a new MQTT user with a custom password: +```bash +docker run --rm -v $(pwd)/mosquitto/config:/temp eclipse-mosquitto mosquitto_passwd -b /temp/pwfile username password +``` + +Then restart the containers: +```bash +docker compose restart mosquitto +``` + ## Development When you run `docker-compose up`, the backend automatically reloads when code changes (`--reload` flag). Just refresh your browser to see updates. diff --git a/docker-compose.yml b/docker-compose.yml index 7cab79a..d290ee8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,8 +5,6 @@ services: build: context: ./backend dockerfile: Dockerfile - ports: - - "${BACKEND_PORT}:8000" volumes: - ./backend/app:/app/app - ./data:/app/data @@ -23,13 +21,38 @@ services: - LABEL_TEMPLATE_ID=${LABEL_TEMPLATE_ID:-vet_label} - LABEL_SIZE=${LABEL_SIZE:-29x90} - LABEL_TEST=${LABEL_TEST:-false} + networks: + - webapps + + mosquitto: + image: eclipse-mosquitto:latest + volumes: + - ./mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro + - ./mosquitto/config/pwfile:/mosquitto/config/pwfile:ro + - mosquitto_data:/mosquitto/data + - mosquitto_logs:/mosquitto/log + environment: + - PUID=1001 + - PGID=1001 + networks: + - webapps frontend: image: nginx:alpine - ports: - - "${FRONTEND_PORT}:80" + container_name: drugsdev volumes: - ./frontend:/usr/share/nginx/html:ro - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro depends_on: - backend + - mosquitto + networks: + - webapps + +volumes: + mosquitto_data: + mosquitto_logs: + +networks: + webapps: + external: true diff --git a/frontend/app.js b/frontend/app.js index 03cede9..ae29bc3 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -394,7 +394,7 @@ function renderDrugs() {
- + diff --git a/mosquitto/config/mosquitto.conf b/mosquitto/config/mosquitto.conf new file mode 100644 index 0000000..d0be93e --- /dev/null +++ b/mosquitto/config/mosquitto.conf @@ -0,0 +1,20 @@ +listener 1883 +listener 9001 +protocol websockets + +persistence true +persistence_location /mosquitto/data/ + +# Authentication +allow_anonymous false +password_file /mosquitto/config/pwfile + +# Logging +log_dest stdout +log_timestamp true +log_type all + +# Performance +max_connections -1 +max_queued_messages 1000 + diff --git a/mosquitto/config/pwfile b/mosquitto/config/pwfile new file mode 100644 index 0000000..a931116 --- /dev/null +++ b/mosquitto/config/pwfile @@ -0,0 +1 @@ +mqtt:$7$1000$x5foCeSdbDKyb+S/CkGI37HWJEIAQil+PfMwREfPHHbRGsUwTWKcoHXcOC4l15mj1HMH8GovYvGGOVDHkOrcBA==$kXYD9LRqSkThHyWTivw8l8/NBdXvpZ9d8qwmIJcGabyrohRdkfXcEgRbEJP7sJ43r6nPX7+p1lb+nF0Actt4ww== diff --git a/nginx.conf b/nginx.conf index 4527cbe..a6e3da6 100644 --- a/nginx.conf +++ b/nginx.conf @@ -16,5 +16,16 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } + + location /mqtt { + proxy_pass http://mosquitto:9001; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } }