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

Host from subpath #95

Closed
mkuf opened this issue Sep 1, 2023 · 8 comments
Closed

Host from subpath #95

mkuf opened this issue Sep 1, 2023 · 8 comments
Labels
Bug Something isn't working

Comments

@mkuf
Copy link
Contributor

mkuf commented Sep 1, 2023

Hi there,

I'd like to host spoolman Api and the Frontend via a proxy under a subpath e.g. http://host/spoolman

Looking at the fastapi documentation (https://fastapi.tiangolo.com/advanced/behind-a-proxy/) this should be possible by adding the --root-path parameter when starting uvicorn but I had no success with that.

This is the example setup I used for testing:

services:
  spoolman:
    image: ghcr.io/donkie/spoolman:edge
    restart: unless-stopped
    command: 
      - "--host"
      - "0.0.0.0"
      - "--port"
      - "8000"
      - "--root-path"
      - "/spoolman"
    volumes:
      - ./data:/home/app/.local/share/spoolman
    ports:
      - 8000:8000
    labels:
      traefik.enable: true
      traefik.http.services.spoolman.loadbalancer.server.port: 8000
      traefik.http.routers.spoolman.entrypoints: web
      traefik.http.routers.spoolman.rule: PathPrefix(`/spoolman`)
      traefik.http.routers.spoolman.middlewares: strip-spoolman@docker
      traefik.http.middlewares.strip-spoolman.stripprefix.prefixes: /spoolman

  traefik:
    image: traefik:v2.5
    command:
      - "--accesslog"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--api=true"
      - "--api.dashboard=true"
      - "--api.insecure=true"
    ports:
      - "80:80"
      - "8080:8080"
    restart: unless-stopped
    volumes:
        - "/var/run/docker.sock:/var/run/docker.sock:ro"

When navigating to http://localhost/spoolman, a blank white page is presented w/ the titlebar showing Spoolman.
The Webapp does not seem to honor the altered root path and requests files from / instead of /spoolman.
image

Api requests get forwarded to the frontend, which is also not the desired behaiour.

~$ curl http://localhost/spoolman/api/v1
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="/favicon.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#DC7734" />
    <meta name="description" content="Spoolman UI" />
    <meta name="robots" content="noindex,nofollow" />
    <title>Spoolman</title>
    <script type="module" crossorigin src="/assets/index-9c13beb6.js"></script>
    <link rel="stylesheet" href="/assets/index-c7b46f6e.css">
  </head>

  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>

  </body>
</html>

To rule out a misconfiguration of the proxy, I tried to access the container directly via its port.
When accessing http://localhost:8000/spoolman, the frontend loads and shows a 404, while a request to the api behaves the same way as described above.

Any guidance on how to achive this, or does this require code changes?

-Markus

@Donkie
Copy link
Owner

Donkie commented Sep 3, 2023

Yeah there's a few issues regarding this. Working on a fix

@Donkie Donkie added the Bug Something isn't working label Sep 3, 2023
@mkuf
Copy link
Contributor Author

mkuf commented Mar 23, 2024

Any update on this?

@joaoachando
Copy link

Hi, any update on this?

I'm trying to run it behind a reverse proxy but cannot make it work...

@Donkie
Copy link
Owner

Donkie commented May 6, 2024

I've looked into this several times and just took another stab at it but it's a lot more complicated problem than it might seem due to the frameworks I've decided to use. Looking at other open source web apps they also often don't seem to support hosting from subpaths for the same reasons, it's overly complex to implement.

Instead you should just host it from a subdomain, like you should. Hosting from a sub path also has security implications. Why can't you use subdomains?

@mkuf
Copy link
Contributor Author

mkuf commented May 7, 2024

Hosting the app via a proxy under a different hostname requires additional steps and adds external dependencies which might break under certain circumstances, namely

  • accessing the application via IP is not possible when a hostname is required
  • A user might not be able to add entries to the nameserver of their local network
  • you'll have to remember a specific hostname instead of just adding e.g. /spoolman to your printers hostname
  • end users usually do not tinker with network related settings, which would increase the learning curve and probably causes additional support requests

Having spoolman listen to a different basePath would make it possible to access it in any given way, no matter the external circumstances. Analogue to having it listen to a specific port without having to remember the port number.
This would make shipping spoolman with other projects easier, which correlates with my usecase.

I'd like to ship spoolman with prind, which is using a proxy for the web frontends as well as moonraker endpoints under the same hostname.
At the moment, spoolman is the odd one out, as it has to be accessed via its specific port as proxying it via a subpath is not possible.

Could you elaborate which security implications this would have?

@kgadberry
Copy link

I would also like to see this implemented, though I understand that it's not as straightforward as it sounds. I would like to be able to access Spoolman without an IP:port. My current setup makes this difficult to do without making the service accessible from the internet, and I would like to keep it only accessible over VPN.

@Donkie Donkie closed this as completed in bc32f1e May 10, 2024
@Donkie
Copy link
Owner

Donkie commented May 10, 2024

I have now pushed a commit that fixes this. If you use docker you can test it out by running the edge tagged image. If you don't use docker you will have to run it from source, I'll create a guide for how to do that.

Set the base path using the SPOOLMAN_BASE_PATH environment variable, see the .env.example file for more details.

@Donkie
Copy link
Owner

Donkie commented May 11, 2024

There are now instructions at the bottom of the README for how to run spoolman from source in a non-docker way.

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

4 participants