Setting proxy server on Minimalist JS App?

1580
4
03-10-2017 01:21 PM
AZendel
Occasional Contributor III

We've downloaded the "Minimalist app" and are customizing it.  We'd like to include map tiles served by sister organization's on-premises ArcGIS Server.  But it's on a completely different domain than the "Minimalist" app, necessitating the use of a proxy URL.  We've successfully configured the proxy in a different project with code like

// Optional array of proxy rules
 PROXY_RULES: [
   {
      urlPrefix: "http://www.our.org/arcgis/rest/services",
      proxyUrl: "http://www.our.org/proxy/proxy.ashx"
   }
 ],‍‍‍‍‍‍‍

But the proxy setting for the minimalist app only has one line to specify the proxy, unless I'm missing something:

"proxyurl": "http://www.our.org/proxy/proxy.ashx",

When I attempt to view the map outside of our domain, I get prompted to log in.  That indicates that the proxy is not configured correctly.

Suggestions?

Thanks,

Alex

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Alex,

   Once you set the minimalist app to use the proxy:

"proxyurl": "http://www.our.org/proxy/proxy.ashx",

then in the actual proxy.config file is where you add your serverUrl to tell the proxy to proxy those url requests.

AZendel
Occasional Contributor III

Thanks, Robert.  I've been out of town.  The Minimalist app doesn't come with a proxy.config file.  Do I need to create one? If so, what code should it contain?  

Or are you referring to the proxy.config file that's often deployed on the server side, like this example?  The server is already configured to forward proxy requests to our sister organization's ArcGIS Server.  Other ArcGIS JS maps on a different domain are successfully consuming that server's tiles.

Thanks again for your help!

Alex 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

  I am referring to the proxy.config that exists in your proxy app on the web server (i.e. the one that is with www.our.org/proxy/proxy.ashx).

Once you have set your proxyurl in the minimalist app do you see the proxy being used when you watch the network traffic?

If you are saying that this minimalist app is on a different server than the proxy and the portal then you should setup a proxy on the same web server as the minimalist app.

AZendel
Occasional Contributor III

The proxy is now functioning correctly after using a hack that we used when we deployed a previous ESRI configurable app.   We added lines 11 and 12 below to the index.html file (not the config/defaults.js file that we attempted in my first post).

 <script type="text/javascript">
        require([
            "config/templateConfig",
            "application/template",
            "application/main"
        ], function(
            templateConfig,
            Template,
            Main
        ){
            //all requests to traffic.arcgis.com will proxy to the proxyUrl defined in this object.
            esri.addProxyRule({ urlPrefix: "http://www.our.org/arcgis/rest/services", proxyUrl: "http://www.our.org/proxy/proxy.ashx" });
            // create the template. This will take care of all the logic required for template applications
            var myTemplate = new Template(templateConfig);
            // create my main application. Start placing your logic in the main.js file.
            var myApp = new Main();
            // start template
            myTemplate.startup().then(function(config) {
                // The config object contains the following properties: helper services, (optionally)
                // i18n, appid, webmap and any custom values defined by the application.
                // In this example we have one called theme.
                myApp.startup(config);
            }, function(error) {
                // something went wrong. Let's report it.
                myApp.reportError(error);
            });
        });
    </script>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

As a test, I commented out the following line in the config/defaults.js file and the tiles behind the proxy server still displayed.

 "proxyurl": "", /* NOTE. We attempted to use this setting here"http://www.our.org/proxy/proxy.ashx", but it didn't work.  Instead we put the proxy line in index.html*/‍‍

In other words, setting the proxy in the defaults.js doesn't seem to be affecting our app at all.  This is the second ESRI configurable app that works fine when specifying both the urlPrefix and proxyURL settings.  This makes me wonder if the Minimalist app is missing the urlPrefix parameter all together.  I'm no javascript excerpt, so I can't say for sure.....

Robert, to answer your last question, we are serving this app from www.organization1.org while the tiles are behind the proxy on www.our.org (actual URLs substituted).   They're on two different servers in two different domains (the former is on a web host provider and the latter is on an on-premises ArcGIS server that's exposed to the web).  Thanks again for your suggestions.

Alex

0 Kudos