version: '3.1'

services:

  db:
    image: mongo
    ports:
      - "27017:27017"
    volumes:
      - ./data:/data/db
    networks:
      - backend-network

  backend:
    image: node:20
    working_dir: /backend
    volumes:
      - ./backend:/backend
    ports:
      - "3000:3000"
    command: ["npm", "run", "start"]
    depends_on:
      - db
    networks:
      - backend-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.backend.rule=Host(`jucundus.saucisse.ninja`) && PathPrefix(`/backend`)"
      - "traefik.http.routers.backend.entrypoints=websecure"
      - "traefik.http.routers.backend.tls=true"
      - "traefik.http.routers.backend.tls.certresolver=myresolver"
      - "traefik.http.services.backend.loadbalancer.server.port=3000"

  client:
    image: nginx:latest
    restart: always
    hostname: jucundus.saucisse.ninja
    ports:
      - "80:80"
    volumes:
      - ./client/dist/angular-material-template:/usr/share/nginx/html
    depends_on:
      - backend
    labels:
      - "traefik.enable=true"
      - "traefik.http.middlewares.redirecthttps.redirectscheme.scheme=https"
      - "traefik.http.middlewares.redirecthttps.redirectscheme.permanent=true"

      - "traefik.http.routers.jucundus-http.rule=Host(`jucundus.saucisse.ninja`)"
      - "traefik.http.routers.jucundus-http.middlewares=redirecthttps"

      - "traefik.http.routers.jucundus.rule=Host(`jucundus.saucisse.ninja`)"
      - "traefik.http.routers.jucundus.tls=true"
      - "traefik.http.routers.jucundus.tls.certresolver=myresolver"
      - "traefik.http.routers.jucundus.tls.domains[0].main=jucundus.saucisse.ninja"
      - "traefik.http.services.scrapper.loadbalancer.server.port=80"

networks:
  backend-network: