dodona-edu / dolos

:detective: Source code plagiarism detection
https://dolos.ugent.be
MIT License
244 stars 31 forks source link

ActiveStorage URL's generated by Dolos API incorrect when hosted on a subdirectory using `relative_url_root`. #1523

Open rien opened 3 months ago

rien commented 3 months ago

Due to a bug in Rails' ActiveStorage (https://github.com/rails/rails/issues/43633), the URL's generated by the API pointing to files stored using ActiveStorage are not on the desired subdirectory if relative_url_root is used.

It is unfortunately our hands to fix this.

Workaround

You can avoid this issue by using another application/proxy to take care of hosting the Dolos API on a subdirectory (like Phusion Passenger's passenger_base_uri), or by adding an extra redirect location from /rails/* to /rails/api/*.

For example for NGINX, the following snippet would host Dolos on https://dolos.localhost:9090:

http {
    upstream dolos-api {
        server api:3000;
    }

    server {
        listen 9090 ssl;
        server_name dolos.localhost;
        ssl_certificate /root/ssl/cert.crt;
        ssl_certificate_key /root/ssl/cert.key;

        # Serve the static front-end files
        location / {
            root /path/to/dolos-web;
        }

        location /api {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Host 'dolos.localhost:9090';
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass http://dolos-api/;
        }

        # Required due to a bug in Rails' ActiveStorage
        location /rails {
            return 302 https://dolos.localhost:9090/api$request_uri;
        }
    }
}