1

I think the answer to this question is "no", but I thought I'd ask here to be sure. I am writing a web application and I need to access JavaScript code from a subdomain on another domain. This isn't allowed by web browsers because it's considered cross-site scripting.

This whole problem would go away if both machines could somehow be mapped to the same domain and just route the individual page requests to the correct place. So http://example.com/App1.aspx and http://example.com/App2.aspx would actually sit on separate machines.

Is this technically possible?

Thanks for any help.

MgSam
  • 141
  • 1
  • 5
  • What do you mean by "access Javascript code"? There are some things you can enable across domains which might make the proxy problem go away. Like [CORS](http://www.html5rocks.com/en/tutorials/cors/) headers for cross domain Ajax calls. – Matt Mar 05 '13 at 19:39
  • Perhaps not stated the most elegant way, but I need to access DOM elements of a page from a sub-domain hosted in an iframe via JavaScript from the top-level domain outside the iframe. From what I understand, CORS requires both domains "agree" to it. I can't modify the page source coming from the sub-domain. – MgSam Mar 05 '13 at 19:44
  • Ah.. well CORS requires some headers to be set on the response from the domain you are sending the request to, your subdomain, to allow the requesting domain access. If you don't control the sub domain server then you'll probably need the proxy for your XSS. If you could add the headers, you can dump the IFrame and load the data into a div with Ajax and modify as needed. – Matt Mar 05 '13 at 19:58

2 Answers2

2

Yes, it's possible to proxy requests to separate nameservers based on a variety of rules.

IIS appears to have such a capability, called Application Request Routing.

ceejayoz
  • 32,910
  • 7
  • 82
  • 106
2

What you're looking for is known as a reverse proxy.

Nginx is a popular open source reverse proxy.

In this scenario you would point example.com's DNS to the proxy which would choose which web server to use based on the content of the request.

Cory J
  • 1,568
  • 5
  • 19
  • 28