简体   繁体   English

全局配置$ http以在angularJS中使用CORS(所有请求的固定域)

[英]Global configuring $http for using CORS in angularJS (fixed domain for all requests)

I have ad restful server and a web server in another domain for serving asset files. 我在另一个域中有广告restful服务器和Web服务器来提供资产文件。

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. 现在我尝试将相对URL更改为Explicit one。

Ordinary solution is changing all used URLs like this: 普通的解决方案是改变所有使用的URL,如下所示:

$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) 是否有任何解决方案为angularJS中的所有$http$resource请求设置固定域(例如在$ httpprovider中)

I really suggest using the Restangular Library if you want functionality like this and a better coding experience. 如果你想要这样的功能和更好的编码体验,我真的建议使用Restangular Library

It allows you to set different base urls for each service you create. 它允许您为您创建的每个服务设置不同的基本URL。

Reference . 参考

While this may not be exactly what you're looking for at the moment, you'll be happy you took my advice. 虽然这可能不是您目前正在寻找的,但您会很高兴接受我的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM