gotify / server

A simple server for sending and receiving messages in real-time per WebSocket. (Includes a sleek web-ui)
https://gotify.net
Other
11.52k stars 639 forks source link

Support for X-Forwarded-Prefix #649

Closed twigley closed 7 months ago

twigley commented 7 months ago

Have you read the documentation?

You are setting up gotify in

Describe your problem

I'm trying to run gotify from behind Traefik on a subpath rather than a subdomain running with a docker-compose stack as:

  gotify:
    container_name: gotify
    image: gotify/server
    volumes:
      - ${CONFIG_PATH}/gotify:/app/data
    labels:
      - traefik.enable=true
      - traefik.http.routers.gotify.rule=PathPrefix(`/gotify`)
      - traefik.http.services.gotify.loadbalancer.server.port=80
      - traefik.http.routers.gotify.middlewares=gotify
      - traefik.http.middlewares.gotify.stripprefix.prefixes=/gotify

Gotify doesn't appear to respect the header X-Forwarded-Prefix mentioned within https://doc.traefik.io/traefik/middlewares/http/stripprefix/#configuration-options so while the index returns a 200 all static objects return a 404 because they revert to the root path rather than the prefixed path e.g

http://mylocal.domain/gotify - returns a 200 HTTP code

http://mylocal.domain/static/js/main.f445756e.chunk.js - Returns a 404 as it's trying to load the asset from the root path, ignoring X-Forwarded-Prefix.

I'm wondering if there's any way around this without code changes to Gotify. I've looked through a few historical issues but not found anything specific to the use of sub paths that might fix it. I can't find any reference to the header in code so I'm presuming it's not utilised, but I'm not a Go dev by any stretch.

Any errors, logs, or other information that might help us identify your problem

Ex: docker-compose.yml, nginx.conf, android logcat, browser requests, etc.

Example logs from Traefik
```
10.*.*.* - - [27/Apr/2024:21:21:41 +0000] "GET /gotify HTTP/1.1" 200 1458 "-" "-" 95080 "gotify@docker" "http://172.22.0.15:8475" 3ms
10.*.*.* - - [27/Apr/2024:21:21:41 +0000] "GET /static/css/2.0f3898ba.chunk.css HTTP/1.1" 404 1282 "-" "-" 95081 "homepage@docker" "http://172.22.0.14:3000" 6ms
10.*.*.* - - [27/Apr/2024:21:21:41 +0000] "GET /static/js/2.a296d629.chunk.js HTTP/1.1" 404 1282 "-" "-" 95082 "homepage@docker" "http://172.22.0.14:3000" 6ms
10.*.*.* - - [27/Apr/2024:21:21:41 +0000] "GET /static/js/main.f445756e.chunk.js HTTP/1.1" 404 1282 "-" "-" 95083 "homepage@docker" "http://172.22.0.14:3000" 6ms
10.*.*.* - - [27/Apr/2024:21:21:41 +0000] "GET /static/js/2.a296d629.chunk.js HTTP/1.1" 404 1282 "-" "-" 95084 "homepage@docker" "http://172.22.0.14:3000" 2ms
10.*.*.* - - [27/Apr/2024:21:21:41 +0000] "GET /static/js/main.f445756e.chunk.js HTTP/1.1" 404 1282 "-" "-" 95085 "homepage@docker" "http://172.22.0.14:3000" 5ms
10.*.*.* - - [27/Apr/2024:21:21:42 +0000] "GET /static/favicon-196x196.png HTTP/1.1" 404 1282 "-" "-" 95086 "homepage@docker" "http://172.22.0.14:3000" 4ms
10.*.*.* - - [27/Apr/2024:21:21:42 +0000] "GET /static/favicon-32x32.png HTTP/1.1" 404 1282 "-" "-" 95087 "homepage@docker" "http://172.22.0.14:3000" 5ms
```

jmattheis commented 7 months ago

Add a trailing slash to all prefixes and the url you're accessing: http://mylocal.domain/gotify/

twigley commented 7 months ago

Add a trailing slash to all prefixes and the url you're accessing: http://mylocal.domain/gotify/

You're a star @jmattheis , it looks like that fixes it within the context of how I'm using it. I'm using homepage so I've just added a trailing slash to the href config for the container and it works now via the sub path. e.g

  gotify:
    container_name: gotify
    image: gotify/server
    environment:
      - TZ=${TIMEZONE}
    volumes:
      - ${CONFIG_PATH}/gotify:/app/data
    labels:
      - traefik.enable=true
      - traefik.http.routers.gotify.rule=PathPrefix(`/gotify`)
      - traefik.http.services.gotify.loadbalancer.server.port=80
      - traefik.http.routers.gotify.middlewares=gotify
      - traefik.http.middlewares.gotify.stripprefix.prefixes=/gotify
      - homepage.group=Management
      - homepage.name=Gotify
      - homepage.icon=gotify.png
      - homepage.href=/gotify/
      - homepage.description=Notifications

Much appreciated!