-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
Handle assets in dashboard when rails app is behind proxy path #424
Comments
@lauer I don't have a lot of experience with configuring a Rails app for a proxy path. Is this descriptive of the configuration that you're using (e.g. It looks like this might be a Rails bug 😞 : rails/rails#31476 Edit: Maybe this is a workaround to pass it explicitly to the URL generators in the dashboard: rails/rails#40237 |
Suggestion; inline all assets (a dashboard doesn't have to look awesome, just ok, so the accompanying assets should be fairly minimal to begin with) and load them on every page render. Skip all hassle around CORS, proxy servers, etc. |
@sandstrom I agree 99%. The assets right now are served statically as if they are regular routes/controllers/actions/views; they do not go through any asset pipeline: good_job/engine/config/routes.rb Lines 8 to 18 in ef1b5a5
good_job/engine/app/views/layouts/good_job/base.html.erb Lines 8 to 13 in ef1b5a5
good_job/engine/app/controllers/good_job/assets_controller.rb Lines 10 to 12 in ef1b5a5
From looking into this issue, I did make an additional assumption: I think all of the paths/links are incorrect/broken, not just the assets (because the assets are linked like any other route/path). It's just that the asset paths are most visibly broken. |
@lauer I was able to find a workaround for fixing GoodJob's Dashboard routes when using Try adding this to an initializer: # config/initializers/good_job.rb
module GoodJobRelativeUrlRoot
def url_options
options = super
script_name = [Rails.application.config.relative_url_root, options[:script_name]].join("")
options.merge(script_name: script_name)
end
end
ActiveSupport::Reloader.to_prepare do
GoodJob::ApplicationController.prepend(GoodJobRelativeUrlRoot)
end Would you be able to give that a try? Thank you 🙏🏻 |
Thanks for this @bensheldon . This helped me solve an issue I had related to rails/rails#31476 |
@tomfast thank you for letting me know! That's fantastic 🎉 I'm also linking in rails/rails#42243. Maybe I'll be able to get a PR upstream in Rails too. |
To write up my discoveries. There are 2 ways to set up a proxy path with nginx (which is how I'm simulating this). (1) Nginx provides subpath (proxy_pass trailing slash)In this configuration, Nginx does not pass the full path to the application, only the subpath when proxy pass is configured with a trailing slash: # nginx.conf
location /api {
proxy_pass http://127.0.0.1:3000/; # <-- with a trailing slash
} When requesting In this circumstance, configuration is solely focused on having Route helpers generate the appropriate urls so that links work. That was my workaround above to override
BUT, this does not seem to be the method that Rails embraces. Judging by Rails Engine Mount Tests, Rails prefers the following... (2) Nginx provides full path (proxy_path slashless)In this configuration, Nginx passes the full path to the application, without the # nginx.conf
location /api {
proxy_pass http://127.0.0.1:3000; # <-- without a trailing slash
} When requesting # config.ru
map '/api' do
run Rails.application
end ...which results in Rack passing to Rails a request with the subpath and In this configuration, GoodJob works perfectly fine with no other configuration or workarounds 👍🏻 BUT, I made a little test route to show what's happening:
All the details
# index.html.erb
<pre>
Rails.application.config.relative_url_root: <%= Rails.application.config.relative_url_root %>
ENV['RAILS_RELATIVE_URL_ROOT']: <%= ENV['RAILS_RELATIVE_URL_ROOT'] %>
request.env['SCRIPT_NAME']: <%= request.env['SCRIPT_NAME'] %>
Rails.application.routes.default_url_options: <%= Rails.application.routes.default_url_options %>
--------------
root_url: <%= root_url %>
root_path: <%= root_path %>
path_to_stylesheet("application"): <%= path_to_stylesheet "application" %>
good_job.root_path: <%= good_job.root_path %>
Rails.application.routes.url_helpers.root_path: <%= Rails.application.routes.url_helpers.root_path %>
GoodJob::Engine.routes.url_helpers.root_path: <%= GoodJob::Engine.routes.url_helpers.root_path %>
--------------
request.env: <%= JSON.pretty_generate request.env %>
--------------
Rails.application.config.action_controller: <%= JSON.pretty_generate Rails.application.config.action_controller %>
</pre> I think this can be fixed, or at least have a simple failing test case in this engine test section by show that |
I've made a Rails PR: rails/rails#45719 |
The fix in rails/rails#45719 has been merged. I don't believe it will be backported, but I think there are enough workarounds in this thread. |
The assets seem to always get fetched from
/good_job/
(mount path)But I have a rails app that is behind a proxy - users url path is
/api/good_job/
Therefore the files can not be loaded.
Would it be possible so the dashboard load the assets files as e.g.
./bootstrap.css
The text was updated successfully, but these errors were encountered: