faiz
November 10, 2022, 8:03am
1
Hello!
I'm trying to achieve following method override using Traefik v2.9 from my docker-compose.yml file. Everything works as expected but one middleware. I'll try to explain it in details below.
The issue is /_admin/hasura
path prefix is not able to replace path to /
of hasura service running on exposed port 8080. But if I enter /_admin/hasura/console
from my browser, it works as expected & I'm able to access hasura service's admin console.
# Below is the bigger picture of the routings
localhost:9090/ --> Traefik Dashboard [Working]
localhost:1337/ --> NextJS Web App [Working]
localhost:1337/api --> NextJS API [Working]
localhost:1337/api/graphql --> GraphQL Engine [Working]
localhost:1337/_admin/hasura --> GraphQL Console [Not Working]
I'm sharing my docker-compose label configs against all the services.
Labels :
Traefik Service [Ports - (Web) 1337:1337 & (Traefik) 9090:8080]:
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--log.level=info"
- "--entrypoints.web.address=:1337"
NextJS Service [Port - 3000:3000]
labels:
- "traefik.enable=true"
# Router : Next UI & API
- "traefik.http.routers.nextjs.entrypoints=web"
- "traefik.http.routers.nextjs.rule=Host(`localhost`) && PathPrefix(`/`)"
- "traefik.http.services.nextjs.loadbalancer.server.port=3000"
Hasura Service [Ports - 8080:8080]:
labels:
- "traefik.enable=true"
# Router : Hasura
- "traefik.http.routers.hasura.entrypoints=web"
- "traefik.http.routers.hasura.rule=(Host(`localhost`) && PathPrefix(`/api/graphql`))"
- "traefik.http.routers.hasura.service=hasura"
- "traefik.http.services.hasura.loadbalancer.server.port=8080"
# Middleware : Hasura
- "traefik.http.middlewares.strip-hasura.replacepathregex.regex=^/api/graphql(.*)"
- "traefik.http.middlewares.strip-hasura.replacepathregex.replacement=/v1/graphql"
# Register Hasura Middleware into Router
- "traefik.http.routers.hasura.middlewares=strip-hasura@docker"
# Router : Console
- "traefik.http.routers.console.entrypoints=web"
- "traefik.http.routers.console.rule=(Host(`localhost`) && PathPrefix(`/_admin/hasura`))"
- "traefik.http.routers.console.service=hasura"
- "traefik.http.services.console.loadbalancer.server.port=8080"
# Middleware : Console
- "traefik.http.middlewares.strip-console.replacepathregex.regex=^/_admin/hasura(.*)"
- "traefik.http.middlewares.strip-console.replacepathregex.replacement=/$$1"
# Register Console Middleware into Router
- "traefik.http.routers.console.middlewares=strip-console@docker"
You are saying one middleware is working and one is not?
Why do you set the „service“ in the hasura container labels?
For debug I would replace hasura with the traefik/whoami container (using port 80, everything else the same) to see what data is send to the container (request, headers, etc.).
faiz
November 10, 2022, 9:56am
3
Ok, I've added traefik/whoami image instead of hasura & have kept the labels as it.
# whoami service
whoami:
image: traefik/whoami
restart: always
command: "--port 2001 --name iamfoo"
depends_on:
- 'traefik'
ports:
- "2001:2001"
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.entrypoints=web"
- "traefik.http.routers.whoami.service=whoami"
- "traefik.http.services.whoami.loadbalancer.server.port=2001"
- "traefik.http.routers.whoami.rule=(Host(`localhost`) && PathPrefix(`/api/graphql`))"
- "traefik.http.middlewares.strip-hasura.replacepathregex.regex=^/api/graphql(.*)"
- "traefik.http.middlewares.strip-hasura.replacepathregex.replacement=/v1/graphql"
- "traefik.http.routers.whoami.middlewares=strip-hasura@docker"
- "traefik.http.routers.whoami-console.rule=(Host(`localhost`) && PathPrefix(`/_admin/hasura`))"
- "traefik.http.middlewares.whoami-console.replacepathregex.regex=^/_admin/hasura/(.*)"
- "traefik.http.middlewares.whoami-console.replacepathregex.replacement=/$$1"
- "traefik.http.routers.console.middlewares=whoami-console@docker"
Now, when I'm hitting http://localhost:1337/_admin/hasura
. I get the output as stated below:
Name: iamfoo
Hostname: 242a5e737b47
IP: 127.0.0.1
IP: 192.168.192.4
RemoteAddr: 192.168.192.3:59948
GET /v1/graphql HTTP/1.1
Host: localhost:1337
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Sec-Gpc: 1
Upgrade-Insecure-Requests: 1
X-Forwarded-For: 192.168.192.1
X-Forwarded-Host: localhost:1337
X-Forwarded-Port: 1337
X-Forwarded-Proto: http
X-Forwarded-Server: 818b14184e0c
X-Real-Ip: 192.168.192.1
X-Replaced-Path: /api/graphql
But, when I hit http://localhost:1337/_admin/hasura
. I get the output as below -
Name: iamfoo
Hostname: 242a5e737b47
IP: 127.0.0.1
IP: 192.168.192.4
RemoteAddr: 192.168.192.3:59948
GET /_admin/hasura HTTP/1.1
Host: localhost:1337
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en
Cache-Control: max-age=0
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Sec-Gpc: 1
Upgrade-Insecure-Requests: 1
X-Forwarded-For: 192.168.192.1
X-Forwarded-Host: localhost:1337
X-Forwarded-Port: 1337
X-Forwarded-Proto: http
X-Forwarded-Server: 818b14184e0c
X-Real-Ip: 192.168.192.1
I see that X-Replaced-Path
isn't available in the one I have issue.
faiz
November 10, 2022, 10:01am
5
I've deleted previous message & changed this message as my detailed response has been now posted by the community team.
Your text (above code) has the same URL twice?