Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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 headers for cross domain Ajax calls. –  mtm Mar 5 '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 5 '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. –  mtm Mar 5 '13 at 19:58

2 Answers 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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.