Setting proxy to work with localhost

3030
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
1 Solution

Accepted Solutions
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>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
10 Replies
RobertScheitlin__GISP
MVP Emeritus

Molly,

   The easiest way to make it work is to just change allowedReferers to "*"

0 Kudos
MKF62
by
Occasional Contributor III

Bummer, I have tried that. I have also tried setting mustMatch to false to no avail.

<ProxyConfig allowedReferers="*"
             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>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Molly,

  So based on your url your localhost is using port 14906? and your proxy in inside your apps folder?

0 Kudos
MKF62
by
Occasional Contributor III

Yes to port number. Proxy is located inside of the app folder. So http://localhost:14906/appName <-- proxy sits in this app.

You gave me an idea though. Do you think I need to edit the urlPrefix in the proxy rule? Currently it is set to the actual production environment.

urlUtils.addProxyRule({
                urlPrefix: "https://www.mydomain.org",
                proxyUrl: "/appName/proxy/proxy.ashx"
            });‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Molly,

   No the urlPrefix is fine if you are only trying to proxy url that are going to https://www.mydomain.org

Have you tried: http://locahost:14906/appName/proxy/proxy.ashx?ping to see if the proxy is working?

0 Kudos
MKF62
by
Occasional Contributor III

Ah, it is not. I get a "Server Error in '/' Application" - resource cannot be found error (404). 

Testing the proxy with the actual domain name (while in the development environment) does respond correctly, so that's working.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Molly,

  Have you set the app folder up as an "application" in IIS?

0 Kudos
MKF62
by
Occasional Contributor III

Yes, it is currently a working MVC application. The stuff I am testing will be a new addition to the application. The JS for the web map is nested inside this MVC application as is the proxy folder. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

I am not sure what is going wrong then. Yoiu have to get the proxy ping working before you can continue though.