Is it possible to force the javascript api _not_ to use the proxy?

1745
6
09-23-2014 04:22 PM
DavidElies
New Contributor III

I'm accessing a private layer from a server that uses an expired certificate (I have no control over this server).  I haven't found a way to allow the proxy page to allow just this one expired certificate and not allow all expired certs.  I want to know if it is possible to force the javascript api to not use the proxy for this layer so that any security problems are handled by the browser.  Hopefully our users will have more influence over the data provider than we do .  We are requesting the legend and while the proxy is not usually used for the layer itself, it always uses the proxy for the legend when using an esriRequest.  I found the corsEnabledServers setting in esri.config.defaults.io and adding the domain to this list seems to keep it from proxying in Chrome, but not in IE9.  The only solution I can think of if we can't stop the api from proxying this request is to use a different ajax request other than esriRequest.  If I have to go that way, does anybody know if there are any concerns with accessing these services with native javascript or other popular library ajax requests: dojo.xhr, jquery.get, etc?

0 Kudos
6 Replies
ArtemisFili
Esri Contributor

It is possible to define the proxy for a set of resources with the same URL prefix. If the request URL matches a rule, then the request will be routed through the proxy. To define a proxy rule specify the url for the proxy and the prefix for the resources that need to be accessed through the proxy.

        urlUtils.addProxyRule({ urlPrefix: "route.arcgis.com", proxyUrl: "<url_to_proxy>" });

This means that you can add proxy rules only for the services that you want to go through the proxy and exclude all the others.

Here is more detailed documentation about the proxy in JavaScript

Using the proxy | Guide | ArcGIS API for JavaScript

0 Kudos
DavidElies
New Contributor III

Thanks for your reply Artemis Fili,

I'm very familiar with addProxyRule.  We use it to force proxying for those layers which need it.  What I'm looking for is a way to force *not* proxying for esriRequests.

0 Kudos
AlexeiB
Occasional Contributor

Good point David, it's something I've been wanting to do for a while as well but unfortunately have not yet found a way.

0 Kudos
AnargyrosTomaras
New Contributor III

The documentation mentions :

You can also specify whether or not the proxy should always be used for communication using alwaysUseProxy

esriConfig.defaults.io.alwaysUseProxy = false;

If it is possible for you to specify specific proxy rules for all services that need a proxy and want to disable it for everything else then theoretically the above should do the trick for you.

What seems to not be supported from the looks of it is disabling the use of the proxy on specific services when a global proxy for all requests is enabled meaning you are forced to know all the proxy-friendly services up front.

0 Kudos
AlexeiB
Occasional Contributor

True, but in my case all of my services have to be secured and only one,

the basemap, is not. Not a big deal just would be nice for convenience.

0 Kudos
Joao_PauloPaschoal
New Contributor II

I've ran into this same issue, have you managed to create this behaviour?

0 Kudos