Vue-resource: Bug about root options

Created on 23 Jan 2016  路  6Comments  路  Source: pagekit/vue-resource

my site is http://bbb.com

I set up root options first link this:

import Vue from 'vue'
import Resource from 'vue-resource'

Vue.use(Resource)

Vue.http.options.root = 'http://aaa.com'  // api server domain

then I use Vue.http to get response like this:

export default {
    getIndex ({data, success, error}) {
        // it will get `http://aaa.com/shop/keyword`, works well
        Vue.http.get('shop/keyword', data).then(success, error)
    }
}

it's work, but when I start url from / it's error

export default {
    getIndex ({data, success, error}) {
        // it will get `http://bbb.com/shop/keyword`, works error
        Vue.http.get('/shop/keyword', data).then(success, error)
    }
}

could u fix it?

Most helpful comment

I think maybe there should be an option to force overrides? I have a server that's providing a REST interface, but I'm using webpack dev server. So I can't make requests like /api/users which will send it to localhost:8080/users/1 instead of myapp.dev/api/users.

As far as I know, the only way to work around this is by using the full URL every time. But that is obviously not a great solution.

All 6 comments

This is the intended behavior, only relative urls are extended with the Vue.http.options.rootoption. Every absolute url starting with /or http will not be modified.

I think if root url is set, it doesn't matter if there any / prefix. So /path have to be joined with root like a path join function does.

I would say this is feature, not bug. What if you wanted to bypass root domain for single request in huge codebase? Also, this somehow feels natural for me, browser handles paths same way for files (HTML/CSS/JS) for example.

If root doesn't have some domains in it but just paths maybe it's right and natural. But for external hosts it's not so clear. Maybe i'm wrong

Maybe we don't need a root at all or need some factory to populate different preconfigured instances (like resources). It seems too complicated so for now we can leave it as is

I think maybe there should be an option to force overrides? I have a server that's providing a REST interface, but I'm using webpack dev server. So I can't make requests like /api/users which will send it to localhost:8080/users/1 instead of myapp.dev/api/users.

As far as I know, the only way to work around this is by using the full URL every time. But that is obviously not a great solution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikeyao picture mikeyao  路  6Comments

jiyifun picture jiyifun  路  3Comments

facesea picture facesea  路  5Comments

christophwolff picture christophwolff  路  6Comments

laizhenhai88 picture laizhenhai88  路  4Comments