[Tuto] Conserver les API deprecated avec un reverse proxy

Vous avez créé un script LUA dont vous êtes fier, un .sh génial, un programme Python hors du commun, un Tuto, c'est ici que vous pouvez les partager.
jjlf
Messages : 43
Inscription : 04 févr. 2018, 20:58

[Tuto] Conserver les API deprecated avec un reverse proxy

Message par jjlf »

Pour ceux qui aurait encore besoin des API deprecated, il suffit de faire un reverse proxy comme ceci avec docker compose par exemple :

docker-compose.yaml

Code : Tout sélectionner

version: '3.7'

services:
  nginx:
    image: nginx:latest
    container_name: domoticz_proxy
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
    restart: unless-stopped
    extra_hosts:
      - "host.docker.internal:192.168.1.XX"


nginx.conf

Code : Tout sélectionner

server {
    listen 80;
    server_name domoticzproxy.local;

   location / {
        proxy_pass http://host.docker.internal:8081/;  # IP et port de Domoticz
        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_redirect off;
    }
    location = /json {
        return 301 /json.htm$is_args$args;
    }
    location /json.htm {
        if ($args ~* "type=settings")        { return 301 /json.htm?type=command&param=getsettings; }
        if ($args ~* "type=users")           { return 301 /json.htm?type=command&param=getusers; }
        if ($args ~* "type=devices")         { return 301 /json.htm?type=command&param=getdevices; }
        if ($args ~* "type=hardware")        { return 301 /json.htm?type=command&param=gethardware; }
        if ($args ~* "type=notifications")   { return 301 /json.htm?type=command&param=getnotifications; }
        if ($args ~* "type=createdevice")    { return 301 /json.htm?type=command&param=createdevice; }
        if ($args ~* "type=scenes")          { return 301 /json.htm?type=command&param=getscenes; }
        if ($args ~* "type=plans")           { return 301 /json.htm?type=command&param=getplans; }
        if ($args ~* "type=scenelog")        { return 301 /json.htm?type=command&param=getscenelog; }
        if ($args ~* "type=mobiles")         { return 301 /json.htm?type=command&param=getmobiles; }
        if ($args ~* "type=cameras_user")    { return 301 /json.htm?type=command&param=getcameras_user; }
        if ($args ~* "type=cameras")         { return 301 /json.htm?type=command&param=getcameras; }
        if ($args ~* "type=schedules")       { return 301 /json.htm?type=command&param=getschedules; }
        if ($args ~* "type=timers")          { return 301 /json.htm?type=command&param=gettimers; }
        if ($args ~* "type=scenetimers")     { return 301 /json.htm?type=command&param=getscenetimers; }
        if ($args ~* "type=setpointtimers")  { return 301 /json.htm?type=command&param=getsetpointtimers; }
        if ($args ~* "type=floorplans")      { return 301 /json.htm?type=command&param=getfloorplans; }
        if ($args ~* "type=lightlog")        { return 301 /json.htm?type=command&param=getlightlog; }
        if ($args ~* "type=textlog")         { return 301 /json.htm?type=command&param=gettextlog; }
        if ($args ~* "type=setused")         { return 301 /json.htm?type=command&param=setused; }
        if ($args ~* "type=graph")           { return 301 /json.htm?type=command&param=graph; }
        if ($args ~* "type=events")          { return 301 /json.htm?type=command&param=events&evparam=$arg_evparam; }
	

      proxy_pass http://192.168.1.45:8081;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
    }
}
Mettre ces 2 fichiers dans un repertoire et ensuite lancer

Code : Tout sélectionner

docker compose up -d
Liste des API deprecated : https://wiki.domoticz.com/Domoticz_API/ ... d_newer%29

Sinon mon expérience du passage à 2025.2 (j'étais en 2025.1 avec zwave js ui déjà) sur Raspberry Pi 3 Model B Rev 1.2
Je suis reparti from scratch sur une nouvelle carte SD j'y ai installé Rapberry OS Trixie minimal (sans desktop) en 64 bit
Une fois OS installé j'ai fait :
sudo apt-get update

Code : Tout sélectionner

sudo bash -c "$(curl -sSfL https://install.domoticz.com)"
sudo apt install docker.io
sudo apt-get install mosquitto
sudo apt install docker-compose
J'ai fait un export de base de donnée de 2025.1 vers 2025.2 : pas de soucis détecté
Pour les package python, on ne peut plus installer directement via pip. Il faut passer par un venv.
J'ai crée en répertoire :
~/Domoticz_Python_Environment
Puis j'installe les dépendances comme ceci :

Code : Tout sélectionner

pip3 install cryptography==3.4.8 requests==2.23.0 charset-normalizer==3.0.1 tinytuya -U -t ~/Domoticz_Python_Environment
Et je mets ceci dans mon ~/.bashrc

Code : Tout sélectionner

export PYTHONPATH=$HOME/Domoticz_Python_Environment:$PYTHONPATH
Pour zwaveJS qui était installé avec snapd, je suis parti sur une install docker compose. J'ai backupé la conf zwave et remis en partage sur le volume docker zwavejs.
Dernière modification par jjlf le 10 juin 2026, 20:43, modifié 1 fois.
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Re: [Tuto] Conserver les API deprecated avec un reverse proxy

Message par Keros »

Merci pour ces explications.

Je viens de déplacer ton message dans un nouveau sujet que j'ai mis dans Tuto. Il aura beaucoup plus de visibilité qu'en étant au milieu de la discussion sur la mise à jour 2025.2.
Comment bien utiliser le forum : Poser une question, Mettre un script, un fichier, une image ou des logs
Mes petits guides : Débuter en programmation, Le débogage, Le choix de matériel, Les sauvegardes
Ma présentation - Mes Tutos
Répondre