Restangular using app context inconsistently

169 Views Asked by At

I have an issue with Restangular using my sites context inconsistently. I have a site running at example.com/app-name. When making the below call I am expecting it to hit example.com/app-name/foo

angular.module('myApp').factory('File', File);
File.$inject = [ 'Restangular' ];
function File(Restangular) {
    var service = {
        postFiles : postFiles
    };
    return service;

    function postFiles(files) {
        return Restangular.all('foo').post(files);
    }
}

However, it hits example.com/foo instead.

While not ideal, I figured I would set the base url for now to work through this issue and then just create a build step to handle the different environment app names.

angular.module('myApp').run(run);
run.$inject = [ 'Restangular' ];
function run(Restangular) {
    Restangular.setBaseUrl('app-name');
}

After this though, it now hits example.com/app-name/app-name/foo.

My current solution to the problem is to do

Restangular.one('app-name').all('foo').post(files)

Which works but, again, will require some build tasks setup to make configurable which is less than ideal.

I've also tried setting the <base> tag to the following:

<base href="/app-name/" />

And the requests still go to example.com/foo instead of example.com/app-name/foo.

Is there something I'm missing in the setup or use of Restangular? Why is the app context being used differently in these two scenarios?

0

There are 0 best solutions below