Global setting $ http to use CORS in angularJS (fixed domain for all requests)

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

In the past, both of these servers were the same and were served on the same server. and now I'm trying to change the relative URLs to Explicit.

A typical solution modifies all the URLs used as follows:

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

instead

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

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

+5
source share
1 answer

I really suggest using Restangular Library if you need such functionality and better coding quality.

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

Link

While this is not exactly what you are looking for at the moment, you will be happy that you accepted my advice.

+1
source

Source: https://habr.com/ru/post/1202735/


All Articles