e7d / speedtest

A self-hosted, lightweight HTML5 speed test implemented in JavaScript, based on Web Workers and XMLHttpRequest.
https://hub.docker.com/r/e7db/speedtest
MIT License
212 stars 58 forks source link

Missing js and css when using a reverse Proxy in a subdirectory #30

Open sherlockedBBC opened 3 years ago

sherlockedBBC commented 3 years ago

Version: 0.5.3

I am using traefik as a reverse proxy in front of speedtest. traefik is configured to forward requests to example.com/speedtest/ to speedtest and strip the /speedtest/ prefix. To speedtest, it looks like it is simply hosted in a root directory.

When accessing the site the HTML is loaded but the icon, js, and CSS files are not loaded because the path is example.com/app.js and not example.com/speedtest/app.js. If I change the path manually in my browser I get a 200 response.

Github Issue

e7d commented 3 years ago

Hi @sherlockedBBC,

Yeah you're right. That is a genuine, that should be relatively simple to fix. I'll give it a look some time and produce a fix.

Regards.

aniqueta commented 3 years ago

Thanks @e7d.

In the meantime, is there a workaround? Trying the following in nginx, which normally works for sub-directories, didn't do the trick for me:

        location /speedtest {
                return 301 $scheme://$host/speedtest/;
        }

        location ^~ /speedtest/ {
                rewrite /speedtest(.*) $1 break;
                proxy_pass http://127.0.0.1:5080;
                client_max_body_size 256M;
        }

        if ($http_referer ~* /speedtest) {
                rewrite ^/(.*) /speedtest/$1? redirect;
        }
JoshMcCullough commented 2 years ago

Also need this. I was able to hack my way around it by doing this in NGINX but it ain't pretty and ain't what we want to do (YMMV):

location ~ "^/(ip|ping|run|config.json|(app|icons|worker)\..{8}\.(css|js|woff|woff2|ttf))$" {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    auth_jwt_enabled off;
    gzip off;
    proxy_pass http://localhost:5080;
}

location /speed-test {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    auth_jwt_enabled off;
    gzip off;
    proxy_pass http://localhost:5080/;
}