Has anyone figured out how to use the proxy? Right now I've got:
var map,
view;
require([
"esri/Map",
"esri/views/SceneView",
"esri/config",
"esri/layers/FeatureLayer",
"dojo/domReady!"
], function(
Map,
SceneView,
esriConfig,
ArcGISDynamicLayer,
FeatureLayer
) {
esriConfig.request.proxyUrl = "proxy/proxy.php";
map = new Map({
basemap : "streets"
});
view = new SceneView({
container : "viewDiv",
map : map
});
overlay = new FeatureLayer("{...}/MapServer/0");
map.add(overlay);
});
... but the proxy is being bypassed. I'm guessing I need to define which URLs get proxied somewhere, and I've played a bit with esri/request, but haven't got anywhere with that either. The only thing that works is using forceProxy=true, and that sends all requests through the proxy. Any thoughts?
Solved! Go to Solution.
Hi Noah,
Thanks for this it was really helpful. It looks as though there are a few inconsistencies at this stage. Most notably, it seems that esriConfig.request.proxyUrl needs to be defined, but left as an empty string. It seems the new API treats protocols differently too - all my URLs started previously with "//" to be protocol agnostic, but the urlPrefix now needs to either define the protocol in full or ignore it altogether (i.e. start with the subdomain / domain / server URL).
The code below kind of works for me... it's not actually showing anything on the map yet, but it does seem to download the data successfully.
Thanks again!
Roland.
var map,
view;
require([
"esri/Map",
"esri/views/SceneView",
"esri/config",
"esri/core/urlUtils",
"esri/layers/FeatureLayer",
"dojo/domReady!"
], function(
Map,
SceneView,
esriConfig,
urlUtils,
FeatureLayer
) {
esriConfig.request.proxyUrl = "";
urlUtils.addProxyRule({
urlPrefix : "{...}",
proxyUrl : "proxy/proxy.php"
});
map = new Map({
basemap : "streets"
});
view = new SceneView({
container : "viewDiv",
map : map
});
overlay = new FeatureLayer("//{...}/MapServer/0");
map.add(overlay);
});
Did you include the URLs you want proxied in your proxy.config file? Which proxy are you using, PHP, DotNET, or JSP?
Hi Kristian,
Yes - it's the PHP proxy (see URL above) and I've just ported it across from a working site that uses JSAPI v3.14 (some code snippets below). I'm using the latest version of the proxy code from GitHub.
I suspect the problem is that I'm not using the JS v4.0 proxy code correctly, but it's difficult to tell. I couldn't find an equivalent for the urlPrefix statement, which might be key here...
Thanks!
Roland.
>>>
define([
'esri/urlUtils'
], function(
urlUtils
) {
urlUtils.addProxyRule({
urlPrefix : "{...}",
proxyUrl : "proxy/proxy.php"
});
I should have noticed the proxy extension. Sorry about that. 😕
Try using the urlUtils like you do in 3.14. The import is different though: It's now "esri/core/urlUtils".
This isn't documented, which means things can change in beta2, so keep an eye out for doc updates related to this in the future betas.
Thanks! I've just tried running with the v3.14 proxy code integrated, but I'm still getting a "token required" error, presumably meaning the proxy isn't being used. Any ideas?
If the proxying is due to follow in a future beta then this isn't urgent - I'm just curious to see it in operation!
Thanks again,
Roland.
var map,
view;
require([
"esri/Map",
"esri/views/SceneView",
"esri/config",
"esri/core/urlUtils",
"esri/layers/FeatureLayer",
"dojo/domReady!"
], function(
Map,
SceneView,
esriConfig,
urlUtils,
FeatureLayer
) {
esriConfig.request.proxyUrl = "proxy/proxy.php";
urlUtils.addProxyRule({
urlPrefix : "{...}",
proxyUrl : "proxy/proxy.php"
});
map = new Map({
basemap : "streets"
});
view = new SceneView({
container : "viewDiv",
map : map
});
overlay = new FeatureLayer("{...}/MapServer/0");
map.add(overlay);
});
Hi Roland,
Can you watch the network tab and see if the request is going through the proxy or not? Also, try to proxy a non-secure resource just to see if the proxy works without passing credentials. I do not have the PHP proxy active, but I can get it to work with the DotNet proxy and a secure Feature Layer as well as a non-secured basemap request with the urlUtils.addProxyRule:
require([
"esri/Map",
"esri/config",
"esri/request",
"esri/core/urlUtils",
"esri/layers/FeatureLayer",
"esri/core/Accessor",
"dojo/domReady!"
], function (Map, esriConfig, request, urlUtils, FeatureLayer){
urlUtils.addProxyRule({
urlPrefix : "sampleserver6.arcgisonline.com",
proxyUrl : "/proxy/proxy.ashx"
});
-Noah
Hi Noah,
Thanks for this it was really helpful. It looks as though there are a few inconsistencies at this stage. Most notably, it seems that esriConfig.request.proxyUrl needs to be defined, but left as an empty string. It seems the new API treats protocols differently too - all my URLs started previously with "//" to be protocol agnostic, but the urlPrefix now needs to either define the protocol in full or ignore it altogether (i.e. start with the subdomain / domain / server URL).
The code below kind of works for me... it's not actually showing anything on the map yet, but it does seem to download the data successfully.
Thanks again!
Roland.
var map,
view;
require([
"esri/Map",
"esri/views/SceneView",
"esri/config",
"esri/core/urlUtils",
"esri/layers/FeatureLayer",
"dojo/domReady!"
], function(
Map,
SceneView,
esriConfig,
urlUtils,
FeatureLayer
) {
esriConfig.request.proxyUrl = "";
urlUtils.addProxyRule({
urlPrefix : "{...}",
proxyUrl : "proxy/proxy.php"
});
map = new Map({
basemap : "streets"
});
view = new SceneView({
container : "viewDiv",
map : map
});
overlay = new FeatureLayer("//{...}/MapServer/0");
map.add(overlay);
});