2

I'm deploying my Angular application in a web server, where the app may live at http://localhost:8080/app-name, or http://foobars.com/, or some other URL. I do not have any guarantees about the absolute path - sometimes the call may need to go to /app-name/foo, sometimes to /foo, sometimes to /foobars/foo. In other words, there is a moving part: /app-name, (empty), /foobars in samples above. Also known as context path.

I know I can use <base> for HTML. I can wrap $http or configure Restangular to prepend context path for all calls.

But there still are cases that I don't yet know how to address. For instance, whenever directive uses a template, it is loaded via bare $http as well.

How can I get $http to always use some specific base path for all requests?

1
  • According to the docs you can add a request transform to modify the request configuration object. Unfortunately, I couldn't find too much info describing the request configuration object, but after taking a quick look through the source, it appears that the url being requested is coming from that config object. Commented Oct 9, 2013 at 20:57

1 Answer 1

2

You will want to configure the $httpProvider to use an Interceptor that modifies the config that the call to $http will use.

See the Interceptors section here: http://docs.angularjs.org/api/ng.$http

This will allow you to control your contextual path in any way you need for all $http calls.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.