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

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

Open
rien opened this issue May 16, 2024 · 0 comments

Comments

@rien
Copy link
Member

rien commented May 16, 2024

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
        location /rails {
            return 302 https://dolos.localhost:9090/api$request_uri;
        }
    }
}
@rien rien added the bug Something isn't working label May 16, 2024
@rien rien removed the bug Something isn't working label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant