Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
js: fixed vue-resource root url based on rails root_url
Browse files Browse the repository at this point in the history
VueResource was not considering any path to be included in
its root url. So when portus was set up using RAILS_RELATIVE_URL_ROOT,
the url requests were wrong and data didn't show up.

To fix this we are now setting VueResource root url based on
rails `root_url` value.

Fixes #1421
  • Loading branch information
vitoravelino committed Sep 18, 2017
1 parent d0c0004 commit f1d47a6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const customActions = {
},
};

const resource = Vue.resource('/namespaces{/id}.json', {}, customActions);
const resource = Vue.resource('namespaces{/id}.json', {}, customActions);

function all(params = {}) {
return resource.get({}, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import VueResource from 'vue-resource';

Vue.use(VueResource);

const resource = Vue.resource('/repositories{/id}.json');
const resource = Vue.resource('repositories{/id}.json');

function get(id) {
return resource.get({ id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import VueResource from 'vue-resource';

Vue.use(VueResource);

const resource = Vue.resource('/tags{/id}.json');
const resource = Vue.resource('tags{/id}.json');

function remove(id) {
return resource.delete({ id });
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/vue-shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Vuelidate from 'vuelidate';
Vue.use(Vuelidate);
Vue.use(VueResource);

Vue.http.options.root = window.API_ROOT_URL;

Vue.http.interceptors.push((_request, next) => {
window.$.active = window.$.active || 0;
window.$.active += 1;
Expand Down
2 changes: 2 additions & 0 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ html
meta content="/favicon/browserconfig.xml" name="msapplication-config"
meta content="#205683" name="theme-color"

javascript:
window.API_ROOT_URL = '#{root_url}';
script src="//cdn.polyfill.io/v2/polyfill.js?features=Array.prototype.some,Array.prototype.findIndex,Array.from"
= javascript_include_tag(*webpack_asset_paths("application"))
= yield :js_header
Expand Down

0 comments on commit f1d47a6

Please sign in to comment.