From 0b7a651e811479dd12ea3308739a1d158d12a0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= Date: Mon, 22 Jan 2018 16:38:49 +0100 Subject: [PATCH] api: take the relative url root into account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- app/assets/javascripts/vue-shared.js | 2 +- app/helpers/application_helper.rb | 8 ++++++++ app/views/layouts/application.html.slim | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/vue-shared.js b/app/assets/javascripts/vue-shared.js index d57ad4f9b..4c8a28979 100644 --- a/app/assets/javascripts/vue-shared.js +++ b/app/assets/javascripts/vue-shared.js @@ -10,7 +10,7 @@ Vue.use(VueResource); Vue.use(EventBus); Vue.use(Alert); -Vue.http.options.root = window.API_ROOT_URL; +Vue.http.options.root = window.API_URL; Vue.http.interceptors.push((_request, next) => { window.$.active = window.$.active || 0; diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index acefb9bcb..a12f791ac 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -12,6 +12,14 @@ def app_host request.env["HTTP_HOST"] end + def app_relative_url_root + ENV["RAILS_RELATIVE_URL_ROOT"] || "" + end + + def app_path + File.join(app_host, app_relative_url_root) + end + def js_route action_name = ACTION_ALIASES[controller.action_name] || controller.action_name diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 250bd90bb..fc01a5833 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -29,7 +29,7 @@ html meta content="#205683" name="theme-color" javascript: - window.API_ROOT_URL = '//#{app_host}'; + window.API_URL = '//#{app_path}'; = javascript_include_tag(*webpack_asset_paths("application")) = yield :js_header