I need help setting up a custom api in a docker-compose

It's fixed. I putted the /api route on the root "/" and now it's working, it's weird. But thank you @bluepuma77 for all the potential solutions and the explanations.

Here is the final docker-compose.yml

version: '3.5'
services:
  traefik:
    image: traefik:v2.10.1
    restart: always
    ports:
      - 80:80
      - 443:443
    command:
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --providers.docker.network=web
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --api.insecure=false
      - --certificatesresolvers.le.acme.email=${LETSENCRYPT_MAIL}
      - --certificatesresolvers.le.acme.storage=/etc/ssl/certs/acme.json
      - --certificatesresolvers.le.acme.tlschallenge=true
      - --log.level=DEBUG
      - --log.filePath=/etc/traefik/traefik.log
      - --log.format=json
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /etc/ssl/certs:/etc/ssl/certs
      - /etc/traefik:/etc/traefik
    networks:
      - web

  detactive_api:
    build: api
    restart: always
    env_file: .env
    ports:
      - 3000:3000
    labels:
      - traefik.enable=true
      - traefik.docker.network=web
      - traefik.http.routers.detactive_api.rule=Host(`${DOMAIN_NAME}`)
      - traefik.http.services.detactive_api.loadbalancer.server.port=3000
      - traefik.http.routers.detactive_api.tls.certresolver=le
      - traefik.http.routers.detactive_api.entrypoints=websecure
    depends_on:
      - db
    networks:
      - web
      - internal

  db:
    image: postgres
    restart: always
    env_file: .env
    ports:
      - 5432:5432
    volumes:
      - ./api/db/init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - internal

  pgadmin:
    image: dpage/pgadmin4
    restart: always
    env_file: .env
    environment:
      - SCRIPT_NAME=/pgadmin
    labels:
      - traefik.enable=true
      - traefik.docker.network=web
      - traefik.http.routers.pgadmin.rule=Host(`${DOMAIN_NAME}`) && PathPrefix(`/pgadmin`)
      - traefik.http.services.pgadmin.loadbalancer.server.port=80
      - traefik.http.routers.pgadmin.tls.certresolver=le
      - traefik.http.routers.pgadmin.entrypoints=websecure
    depends_on:
      - db
    networks:
      - web
      - internal

networks:
  web:
    external: true
  internal:
    external: false

Is you api running inside your container at /api? Otherwise it does not work, because Traefik will of course forward the path in the request. You could use StripPrefix middleware.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.