Cross-domain issue when scripting ArcGIS server administration

Discussion created by greenkarmic on Oct 21, 2013

I've dealt with cross-domain issues in the past when using the ArcGIS API for Javascript and Flex (Using a proxy.php and the crossdomain.xml respectively), but I'm unsure how to deal with this one.

I created a simple web page so that admin users could easily perform arcgis server task, and I want to use the ArcGIS Server Administrator API to do so from my Javascript in the page.

Here's the typical error message I get at this moment:

XMLHttpRequest cannot load http://azivm2k8sqlexp:6080/arcgis/admin/generateToken. Origin is not allowed by Access-Control-Allow-Origin. 

How do I tell the REST API at port 6080 to accept my cross-domain calls?
I'm using ArcGIS Server 10.1


Edit: For now I decided to just add a Proxy rule in my web server's (Apache httpd) configuration that will forward requests appropriately without a cross-domain issue:

ProxyPass /arcgis http://azivm2k8sqlexp:6080/arcgis
ProxyPassReverse /arcgis http://azivm2k8sqlexp:6080/arcgis

and I replaced the URL in my javascript code to point to instead of http://azivm2k8sqlexp:6080/arcgis/admin. It works, but I dislike this workaround because it would be much simpler for the client to change the ArcGIS server URL (if need be) in the simple config.js file I prepared for them instead of playing with the web server configuration. Will update if I find another solution later. In the meantime, please let me know if there is a simple/better solution then this.