Skip to content

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

@rien

Description

@rien

Due to a bug in Rails' ActiveStorage (rails/rails#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			
    		proxy_redirect $scheme://$host/rails /api/rails;
		 	# Possibly required when hosting on a non-standard port
    		# proxy_redirect $scheme://$host/ /;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions