mikitex70 / redmine_drawio

Macro plugin to embed draw.io diagrams into Redmine wiki pages
MIT License
125 stars 51 forks source link

redmineUrl is not set correctly if RAILS_RELATIVE_URL_ROOT used #126

Closed Nachtlichtermeer closed 1 year ago

Nachtlichtermeer commented 1 year ago

to use redmine with sub-URLs we changed in config.ru

- run Rails.application
+ map ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
+   run Rails.application
+ end

and in config/environment.rb

Rails.application.initialize!

+ ActionController::Base.relative_url_root = RedmineApp::Application.routes.default_scope
+ Redmine::Utils::relative_url_root = RedmineApp::Application.routes.default_scope

+ ENV['RAILS_RELATIVE_URL_ROOT'] = "/"
+ Redmine::Utils::relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']

now it is not possible to save a diagram.

error in browser: Quellübergreifende (Cross-Origin) Anfrage blockiert: Die Gleiche-Quelle-Regel verbietet das Lesen der externen Ressource auf https://uploads.json/?filename=test_1.png. (Grund: CORS-Anfrage schlug fehl). Statuscode: (null).

uploads.json as host is wrong. So i checked the code and found out that something is wrong with redmine_url

workaround:

--- a/lib/redmine_drawio/hooks/view_hooks.rb
+++ b/lib/redmine_drawio/hooks/view_hooks.rb
@@ -75,7 +75,7 @@ module RedmineDrawio
                     <script type=\"text/javascript\">//<![CDATA[
                         var Drawio = {
                         settings: {
-                            redmineUrl: '#{redmine_url}',
+                            redmineUrl: '/',
mikitex70 commented 1 year ago

Hi @Nachtlichtermeer, what version of Redmine are you using? Windows or Linux? Is Redmine running in a container or in a server/pc? What kind of web server are you using (Apache+Passenger, Nginx+gunicorn, , ...)? I need some info to be able to diagnose the issue. My development environment is based on Redmine 5.0.1 and it works fine in /redmine without touching config.ru or config/environment.rb. The only changed file I sees is config/unicorn.rb which contains the line ENV['RAILS_RELATIVE_URL_ROOT'] = "/redmine". The production environment also works on /redmine without issues, and is an old 3.3.2. In the weekend I will do some testing, but the diagram saving is working with sub-paths since Redmine 3.0.0 and the first releases of the plugin.

Nachtlichtermeer commented 1 year ago

Thanks for reply

I use Redmine 5.0.5 with docker (https://hub.docker.com/_/redmine/) behind Traefik on the same machine and Apache as edge-proxy. To get sub-URLs and mail-send working, i changed the start-command to:

    command: >
      bash -c "echo -e \"require ::File.expand_path('../config/environment',  __FILE__)\\nmap ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do\\n  run Rails.application\\nend\" > config.ru &&
               echo -e \"\\n\\nActionController::Base.relative_url_root = RedmineApp::Application.routes.default_scope\\nRedmine::Utils::relative_url_root = RedmineApp::Application.routes.default_scope\\n\\nENV['RAILS_RELATIVE_URL_ROOT'] = \\\"${RAILS_RELATIVE_URL_ROOT}\\\"\\nRedmine::Utils::relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']\" >> config/environment.rb &&
               echo -e \"default:\\n  email_delivery:\\n    delivery_method: :smtp\\n    smtp_settings:\\n      address: "${SMTP_SERVER}"\\n      port: 25\\n      enable_starttls_auto: true\" > config/configuration.yml &&
               /docker-entrypoint.sh rails server -b 0.0.0.0"

yes, a bit hacky, but at the moment the only way to get all working. RAILS_RELATIVE_URL_ROOT is here set to '/'. So this hack is not necessary but i use the same stack (we use docker swam) for some redmines

mikitex70 commented 1 year ago

Hi @Nachtlichtermeer, I've done some test with the sameersbn/redmine:5.0.5 docker image which I use for development and I don't have issues. Inside the container I see this config.ru:

require ::File.expand_path('../config/environment', __FILE__)

map ENV['RAILS_RELATIVE_URL_ROOT'] || "/" do
  run RedmineApp::Application
end

while the config/environment.rb ends with:

Rails.application.initialize!

and in config/unicorn.rb there is:

ENV['RAILS_RELATIVE_URL_ROOT'] = "/redmine"

Could you try the sameersbn/redmine:5.0.5 image to see if it works better? Maybe you can discover what are the differences in the configuration.

Nachtlichtermeer commented 1 year ago

with sameersbn/redmine:5.0.5 it works i'll test it now with the official image without my RAILS_RELATIVE_URL_ROOT-Hack and without traefik in front of

Nachtlichtermeer commented 1 year ago

it works with redmine:5 with and without Traefik but RAILS_RELATIVE_URL_ROOT-hack so problem is the command for RAILS_RELATIVE_URL_ROOT because of official image does not support change of RAILS_RELATIVE_URL_ROOT. But usage of other images in production is not possible because of iso 27001 for us