garethgeorge / backrest

Backrest is a web UI and orchestrator for restic backup.
GNU General Public License v3.0
1.72k stars 50 forks source link

Ability to change Base URL #424

Open jonpas opened 3 months ago

jonpas commented 3 months ago

Is your feature request related to a problem? Please describe. Running Backrest in a Docker container behind Traefik and wanting to host it on http://home-server/backrest.

Describe the solution you'd like Environment variable BACKREST_BASE_URL which I would set to BACKREST_BASE_URL=/backrest.

Additional context Base URL of ./ works when we can specify where to host it from, but that is harder behind a reverse proxy where we want it accessible from a different URL than the app believes it is serving on.

garethgeorge commented 3 months ago

Hey, what version of backrest are you running?

Reverse proxies with non-base path are definitely intended to be supported. I'm surprised that CSS / assets aren't loading correctly w/path stripping.

<!doctype html><html><head><script type="module" src="index.runtime.7cb06d85.js"></script><title>Backrest</title><link rel="stylesheet" href="index.7c36ca54.css"></head><body> <div id="app"></div> <script src="index.dd3b7407.js" type="module"></script> </body></html>

Is the current web app src loading the various JS sources etc, all of those should be relative imports e.g. in my test install I inserted a /foo prefix

image

jonpas commented 3 months ago

latest Docker image.

Here is my Compose:

  backrest:
    image: garethgeorge/backrest:latest
    environment:
      - BACKREST_DATA=/data
      - BACKREST_CONFIG=/config/config.json
      - XDG_CACHE_HOME=/cache
    volumes:
      - ./data:/data
      - ./config:/config
      - ./cache:/cache
    #ports:
    #  - 9898:9898/tcp
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.backrest.rule=Host(`myserver`) && PathPrefix(`/backrest`)"
      - "traefik.http.routers.backrest.entrypoints=web"
      - "traefik.http.routers.backrest.priority=100"
      - "traefik.http.routers.backrest.middlewares=lan-only@file,backrest-strip"
      - "traefik.http.middlewares.backrest-strip.stripprefix.prefixes=/backrest"

Resulting in blank page with the following in console:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://myserver/index.runtime.7cb06d85.js. (Reason: CORS request did not succeed). Status code: (null).

Module source URI is not allowed in this document: “http://myserver/index.runtime.7cb06d85.js”. [backrest:1:82](http://myserver/backrest)
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://myserver/index.dd3b7407.js. (Reason: CORS request did not succeed). Status code: (null).

Module source URI is not allowed in this document: “http://myserver/index.dd3b7407.js”. [backrest:1:244](http://myserver/backrest)

Showing it's trying to load data from http://myserver/.

I am unsure if there is another way to configure it, as inside the container Backrest has no idea about any prefix, only Traefik reverse proxy does.

garethgeorge commented 2 months ago

Sorry it's hard for me to tell what might be going on here since I'm not very familiar with Traefik and can't tell from the logs why a CORS error might be popping up.

jonpas commented 2 months ago

Essentially, even with the above config, backrest is still trying to load assets from root, eg. https://myserver.index.runtime.7cb06d85.js.