Setting proxy to work with localhost

3043
10
Jump to solution
11-26-2018 10:33 AM
MKF62
by
Occasional Contributor III

I'm trying to use my development environment to work on some things and currently the data on my map gets loaded through a proxy service. The proxy isn't set up to allow a localhost referrer so I would like to do so. I think this would be possible but I'm struggling to get it to work. I get a 404 error. Request URL comes out looking like this:

http://locahost:14906/appName/proxy/proxy.ashx?https://www.mydomain.org/myserver/rest/services/Habit...

Current config file:

<ProxyConfig allowedReferers="https://www.mydomain.org/*,http://localhost:14906/*"
             mustMatch="true"
             logFile="proxyLog.txt"
             logLevel="Warning">
    <serverUrls>
      <serverUrl url="https://www.mydomain.org/myserver/rest/services/HabitatManagement/HabitatManagement/GPServer"
                 username="xxx"
                 password="xxx"
                 matchAll="true"/>
      <serverUrl url="https://www.mydomain.org/myserver/rest/services/HabitatMonitoring/HabitatData/MapServer"
                 username="xxx"
                 password="xxx"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.org/myserver/rest/services/HabitatMonitoring/HabitatClassification/GPServer"
                 username="xxx"
                 password="xxx"
                 matchAll="true" />
    </serverUrls>
</ProxyConfig>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Do I need to add localhost somehow as serverUrls? I'm not sure how that would look because accessing my rest services from localhost uses the same server URLs seen in the above code. You can't access them like "http://localhost:14906/myserver/rest/services/...."

0 Kudos
10 Replies
MKF62
by
Occasional Contributor III

I figured it out. The proxy folder does sit in the application, however when I run it in the development environment it doesn't take the name of the application into account, so the proxyRule in my JS needed to be tweaked a little:

//Got rid of the appName before the /proxy in proxyUrl property
urlUtils.addProxyRule({
                urlPrefix: "https://www.mydomain.org",
                proxyUrl: "/proxy/proxy.ashx"
            });‍‍‍‍‍

Works with this in proxy config file:

<!--For testing in development environment-->
<ProxyConfig allowedReferers="*"
             mustMatch="true"
             logFile="proxyLog.txt"
             logLevel="Warning">
    <serverUrls>
      <serverUrl url="https://www.mydomain.com/myserver/rest/services/HabitatManagement/HabitatManagement/GPServer"
                 username="xxx"
                 password="xxx"
                 matchAll="true"/>
      <serverUrl url="https://www.mydomain.com/myserver/rest/services/HabitatMonitoring/HabitatData/MapServer"
                 username="xxx"
                 password="xxx"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myserver/rest/services/HabitatMonitoring/HabitatClassification/GPServer"
                 username="xxx"
                 password="xxx"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myserver/rest/services/PrintHabitatMaps/PrintHabitatMap/GPServer"
                 username="xxx"
                 password="xxx"
                 matchAll="true" />
    </serverUrls>
</ProxyConfig>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos