Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting static content on different domain from webservices, how to avoid cross-domain?

We've recently been working on a fairly modern web app and are ready to being deploying it for alpha/beta and getting some real-world experience with it.

We have ASP.Net based web services (Web Api) and a JavaScript front-end which is 100% client-side MVC using backbone.

We have purchased our domain name, and for the sake of this question our deployment looks like this:

webservices.mydomain.com (Webservices)

mydomain.com (JavaScript front-end)

If the JavaScript attempts to talk to the webservices on the sub-domain we blow up with cross domain issues, I've played around with CORS but am not satisfied with the cross browser support so I'm counting this out as an option.

On our development PC's we have used an IIS reverse proxy to forward all requests to mydomain.com/webservices to webservices.mydomain.com - Which solves all our problems as the browser thinks everything is on the same domain.

So my question is, in a public deployment, how is this issue most commonly solved? Is a reverse proxy the right way to do it? If so is there any hosted services that offer a reverse proxy for this situation? Are there better ways of deploying this?

I want to use CloudFront CDN as all our servers/services are hosted with Amazon, I'm really struggling to find info on if a CDN can support this type of setup though.

Thanks

like image 398
Tyler Avatar asked Mar 17 '12 00:03

Tyler


1 Answers

What you are trying to do is cross-subdomain calls, and not entirely cross-domain. That are tricks for that: http://www.tomhoppe.com/index.php/2008/03/cross-sub-domain-javascript-ajax-iframe-etc/

As asked how this issue is most commonly solved. My answer is: this issue is commonly AVOIDED. In real world you would setup your domains such as you don't need to make such ways around just to get your application running or setup a proxy server to forward the calls for you. JSONP is also a hack-ish solution.

like image 102
Israel Lot Avatar answered Nov 01 '22 13:11

Israel Lot