Subdirectory support?
starlightknight opened this issue · 6 comments
Thanks for creating this cool project!
Is it possible to configure this container to serve its content out of a subdirectory?
I would like serve this app, along with other admin/monitoring tools, out of admin.mydomain.com behind a reverse proxy like nginx. But after configuring it to proxy_pass to this application's container, the application's javascript will still try to hit /apis/ on the root directory, causing it to fail to load the dashboard.
It would be great if I could pass an argument to this container to say serve out of /subdirectory/ as it would make proxy configuration easy and painless.
I'm not sure if that's an issue with the code or your configuration. The code looks for window.location.host
+ '/apis', which should return the whole host including the subdomain. You see that at request.js line 4.
Hi,
I do not do much javascript development, but from what you described, I believe using window.location.host is the problem.
To clarify, I was referring to subdirectory support, not subdomain. I would like to have one internal subdomain - admin.mydomain.com. On the subdomain i deploy multiple internal tools to subdirectories - so think of other administrative tools like phpmyadmin.
That means I would like to serve as follows:
http://admin.mydomain.com/visualizer
http://admin.mydomain.com/phpmyadmin
This cuts down on managing dns, ssl, and firewall rules for "internal" or ip restricted tools. Normally this is fairly simple with Apache/Nginx/HAProxy proxy http modules. However, what happens with this application is the javascript generated urls will always request /apis at the root of domain, regardless of where it is served from via a proxy.
From what you said about window.location.host + /api - i believe that's the problem.
If i access through a proxy at /visualizer and open the javascript console and do the following, I get:
window.location.host
"admin.mydomain.com"
window.location.href
"http://admin.mydomain.com/visualizer"
This means it goes to http://admin.mydomain.com/api - which does not get proxied correctly. The proxy cannot rewrite this url correctly on reverse proxy, because its generated by the javascript in the user's browser at runtime - it doesn't go through the reverse proxy in a way can be caught by the rewrite.
It seems that using host will always make you write the request to the root of the subdomain - but using href would pick up the subdir too allowing you to proxy from a subdirectory.
To reproduce, here is a stripped down config with HAProxy as follows:
haproxy.cfg
global
log 127.0.0.1 local0 notice
maxconn 1024
daemon
stats socket /tmp/proxystats level admin
resolvers docker
nameserver swarm 127.0.0.11:53
nameserver dnsmasq 127.0.0.1:53
hold valid 1s
defaults
default-server init-addr last,libc,none
log global
mode http
option httplog
option dontlognull
timeout connect 5000
option forwardfor
option http-server-close
frontend http
mode http
timeout client 30000
bind *:80
acl LOCALNET src 10.0.0.0/8 192.168.0.0/16 172.16.0.0/12
# /phpmyadmin
acl phpmyadmin path_dir /phpmyadmin
use_backend phpmyadmin if phpmyadmin LOCALNET
# /visualizer
acl visualizer path_dir /visualizer
use_backend visualizer if visualizer LOCALNET
backend phpmyadmin
mode http
timeout server 30000
reqirep ^(GET|POST|HEAD)\ /phpmyadmin(.*) \1\ /\2
server phpmyadmin phpmyadmin:80 check resolvers docker resolve-prefer ipv4
backend visualizer
mode http
timeout server 30000
reqirep ^(GET|POST|HEAD)\ /visualizer(.*) \1\ /\2
server docker-swarm-visualizer docker-swarm-visualizer:8080 check resolvers docker resolve-prefer ipv4
docker-compose.yaml
version: "3"
services:
docker-swarm-visualizer:
image: manomarks/visualizer:latest
ports:
- "8081:8080/tcp"
networks:
- internal
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
haproxy:
image: haproxy:1.7.2-alpine
ports:
- "80:80/tcp"
- "443:443/tcp"
networks:
- internal
volumes:
- "./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg"
deploy:
mode: replicated
replicas: 1
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
environment:
- PMA_HOST=mysql
- PMA_USER=root
- PMA_PASSWORD=password
- PMA_ABSOLUTE_URI=https://admin.mydomain.com/phpmyadmin
networks:
- internal
deploy:
mode: replicated
replicas: 1
networks:
internal:
driver: overlay
Ah I see. Thanks for clarifying. It should be easy I'll look into it.
+1
seeing the same issue behind NGINX when a location is proxied, i.e. /oam/swarm -> proxy_pass http://swam-visualizer:8080
Any plans to release a new version of visualizer that has this fix?