Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] not compatible with traefik reverse proxy && PathPrefix(/pwgen) #91

Open
E-J-D opened this issue Oct 8, 2024 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@E-J-D
Copy link

E-J-D commented Oct 8, 2024

Describe the bug
Using pwgen behind a traefik reverse proxy with && PathPrefix(/pwgen) function breaks the ui.

To Reproduce
Steps to reproduce the behavior:
Use docker compose file

``

services:
  pwgen:
    image: jocxfin/pwgen:latest
    container_name: pwgen
    ports:
      - 5069:5069
    environment:
      - NO_API_CHECK=false
      - PW_LENGTH=16
      - PW_INCLUDE_UPPERCASE=true
      - PW_INCLUDE_DIGITS=true
      - PW_INCLUDE_SPECIAL=true
      - PW_EXCLUDE_HOMOGLYPHS=true
      - PP_WORD_COUNT=4
      - PP_CAPITALIZE=true
      - PP_SEPARATOR_TYPE=dash
      - PP_USER_DEFINED_SEPARATOR='+'
      - PP_MAX_WORD_LENGTH=5
      - PP_INCLUDE_NUMBERS=true
      - PP_INCLUDE_SPECIAL_CHARS=false
      - PP_HIDE_LANG=true
      - MULTI_GEN=true
      - GENERATE_PP=true
      - ROBOTS_ALLOW=false

    labels:
      - "traefik.enable=true" #
      - "traefik.http.routers.pwgen.entrypoints=web,websecure"
      **- "traefik.http.routers.pwgen.rule=Host(`sub.domain.de`) && PathPrefix(`/pwgen`)"**
      - "traefik.http.routers.pwgen.service=pwgen-service"
      - "traefik.http.routers.pwgen.tls.certresolver=letsencrypt"
      - "traefik.http.routers.pwgen.tls=true"
      - "traefik.http.services.pwgen-service.loadbalancer.server.port=5069"

# https://iceburn.medium.com/reverse-proxy-in-traefik-with-subdirectories-eef4261939e
      - "traefik.http.routers.pwgen.middlewares=pwgen-stripprefix"
      - "traefik.http.middlewares.pwgen-stripprefix.stripprefix.prefixes=/pwgen"

# https://community.traefik.io/t/web-page-behind-traefik-2-3-shows-partially/7958/3
      - "traefik.http.routers.pwgen.middlewares=pwgen-redirectregex, pwgen-replacepathregex"
      - "traefik.http.middlewares.pwgen-replacepathregex.replacepathregex.regex=^/pwgen/(.*)"
      - "traefik.http.middlewares.pwgen-replacepathregex.replacepathregex.replacement=/$$1"
      - "traefik.http.middlewares.pwgen-redirectregex.redirectregex.regex=^(.*)/pwgen$$"
      - "traefik.http.middlewares.pwgen-redirectregex.redirectregex.replacement=$$1/pwgen/"

    networks:
      proxy: null
    restart: always

networks:
  proxy:
    external: true
`

The container starts and traefik routes the https://sub.domain.de/pwgen request to the container, but the ui is broken.

Expected behavior
Ui should be the same as browsing to the internal container IP e.g. http://10.200.100.1:5069 which works perfectly.

Screenshots
grafik

Desktop (please complete the following information):

  • OS: Win11
  • Browser: Firefox 131 / Chrome 129

Would love to use pwgen in my docker enviroment which is handled by traefik as a reverse proxy and handles multiple container as a path instead of subdomains.

@E-J-D E-J-D added the bug Something isn't working label Oct 8, 2024
@jocxfin
Copy link
Owner

jocxfin commented Oct 12, 2024

Hey! Thanks for the report. I haven't used traefik myself, so can't really debug this. Are there any console logs or anything from the browser? First thing that pops into my head is some kind of CORS limitation within traefik. I tried this with cloudflare tunnel and it seems to work just fine. Although there seems to be some kinds of issues with previous prs, so I might have to roll back some changes. I'll let you know. I also don't have much time to develop this, but I'll try my best!

@veerendra2
Copy link

veerendra2 commented Nov 8, 2024

Hi @E-J-D, you need to set BASEA_PATH in environmental variables (For example; BASE_PATH=/pwgen) and don't have to add stripprefix or redirectregex, because the app is already aware of the base path(BASEA_PATH).

So, you just have to add PathPrefix in traefik labels like below

...
    labels:
     ...
      - traefik.http.routers.pwgen.rule=Host(`${MY_DOMAIN}`) && PathPrefix(`/pwgen`)
    environment:
      BASE_PATH: "/pwgen/"

NOTE: While setting environmental variable BASE_PATH, make sure end with trailing slash(/) i.e. BASE_PATH: "/pwgen/" otherwise it won't generate the password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants