How can I have a website on example.com and have a seperate container on example.com/api?

Hi, pretty much, title. I'm currently doing this:

  frontend:
    labels:
      - "traefik.http.routers.mci.rule=Host(`example.com`)"
      - "traefik.http.routers.mci.tls=true"
      - "traefik.http.routers.mci.priority=10"
      - "traefik.http.routers.mci.tls.certresolver=lets-encrypt"
      - "traefik.port=80"
  api:
    labels:
      - "traefik.http.routers.mcib.rule=Host(`example.com`) && PathPrefix(`/api/`)"
      - "traefik.http.routers.mcib.tls=true"
      - "traefik.http.routers.mcib.priority=100"
      - "traefik.http.routers.mcib.tls.certresolver=lets-encrypt"
      - "traefik.port=80"

And currently, when I visit example.com/api/*, it shows me a 404 page from my frontend. However, I want that to be from the API. How would I do that?

In general it looks okay. You don’t need to set priority as the priority defaults to the rule length. Longer rule, more characters, higher priority.

Maybe compare to simple Traefik example.

Well, it doesn't work as expected for me. I don't want the frontend 404 but rather the API usage. So if I fetch example.com/api/foo?bar=foo, I just get a 404 back.

Enable access log in JSON format to see if the error comes from Traefik or your target service.

It's from my app. I get some HTML back.

If you are sure it’s from your app, then maybe it’s not configured for the domain name and expects a different one in the request. Or the path is wrong. You would need to check the logs of the app.