services:
  preview-app:
    container_name: ai-code-app-preview
    image: node:${NODE_VERSION:-22.22.2}-bookworm
    user: "${HOST_UID:-1000}:${HOST_GID:-1000}"
    working_dir: /app
    ports:
      - "${PREVIEW_APP_PORT:-4173}:5173"
    volumes:
      - ./:/app
      - preview-app-hidden-dotdocker:/app/.docker
      - preview-app-hidden-etc-servers:/app/etc/servers
      - ./.docker/preview-app/node_modules:/app/node_modules
      - ./.docker/preview-app/home:/home/how2ice
    networks:
      - default
      - work-backend
    environment:
      HOME: /home/how2ice
      NPM_CONFIG_CACHE: /home/how2ice/.npm
      PORT: 5173
      WORK_SERVER_URL: ${WORK_SERVER_URL:-http://work-server:3100}
      VITE_DISABLE_APP_UPDATE: "true"
      VITE_PUBLIC_HMR_HOST: preview.sm-home.cloud
      VITE_PUBLIC_HMR_PROTOCOL: wss
      VITE_PUBLIC_HMR_CLIENT_PORT: 443
      VITE_DISABLE_PWA: "true"
    command: >
      sh -c "npm ci --legacy-peer-deps && npm run dev -- --host 0.0.0.0 --port 5173"
    restart: unless-stopped

volumes:
  preview-app-hidden-dotdocker:
  preview-app-hidden-etc-servers:

networks:
  work-backend:
    external: true
