5

I have ad restful server and a web server in another domain for serving asset files.

In past both of this servers was same and serves in one server. and now I try to change the relative URLs to Explicit one.

Ordinary solution is changing all used URLs like this:

$http.post(DATA_SERVER_DOMAIN+"/service/method" )

instead of

$http.post("/service/method" )

is there any solution to set fixed domain for all $http or $resource requests in angularJS (for example in $httpprovider)

4
  • I'd go with encapsulating all the service requests inside a $resource. Then you just use the full URI in there Commented Sep 17, 2014 at 6:19
  • 1
    You can look at $http request interceptor concept. But you need a mechanism, where you can differential between a your api request vs requests made by framework itself Commented Sep 17, 2014 at 6:34
  • I concur with @Phil, and would attempt to wrap requests in a $resource (or $service) Commented Sep 17, 2014 at 7:05
  • 1
    Take a look at stackoverflow.com/questions/18984518/… Commented Sep 17, 2014 at 8:21

1 Answer 1

1

I really suggest using the Restangular Library if you want functionality like this and a better coding experience.

It allows you to set different base urls for each service you create.

Reference.

While this may not be exactly what you're looking for at the moment, you'll be happy you took my advice.

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.