Avoid Proxy page for Print Task, Print Template; Geometry Service

1935
13
11-09-2016 02:24 PM
PitersonPaulgek
New Contributor III

Hi there,

Is it possible to avoid using proxy page when

1) create pdf file with Print Task, Print Template?

2) use Geometry Service for Buffer

Any help would be appreciated.

esriConfig.defaults.geometryService = new GeometryService("some URL");

   

esriConfig.defaults.io.proxyUrl = "/proxy/"; - HERE WE MUST PUT CORRECT ADDRESS

esriConfig.defaults.io.alwaysUseProxy = false;

0 Kudos
13 Replies
RobertScheitlin__GISP
MVP Emeritus

Pieterson,

  Any particular reason why? You do not have to use a proxy when using the PrintTask but the use the proxy will be necessary when buffering a complex polygon as the text limit for url params will likely be exceeded and the use of a put request will need to be made.

0 Kudos
PitersonPaulgek
New Contributor III

Thanks for reply, Robert.

How I configure PrintTask not to use proxy?

We have an error

init.js:140 GET http://localhost:55549/proxy/?https://user.domain.com/arcgis/rest/services/DownloadWebMap/GPServer/E... 404 (Not Found)

when run the JavaScript

app.printUrl = "some URL";
var printInfo = esriRequest({
 "url": app.printUrl,
 "content": { "f": "json" }
});

printInfo.then(handlePrintInfo, handleError);

function handlePrintInfo(resp) {
var layoutTemplate, templateNames, mapOnlyIndex, templates;

layoutTemplate = arrayUtils.filter(resp.parameters, function (param, idx) {
return param.name === "Template123";
});

if (layoutTemplate.length === 0) {
console.log("print service parameters name for templates must be \"Template123\"");
return;
}
templateNames = layoutTemplate[0].choiceList;

// remove the MAP_ONLY template then add it to the end of the list of templates
mapOnlyIndex = arrayUtils.indexOf(templateNames, "MAP_ONLY");
if (mapOnlyIndex > -1) {
var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0];
templateNames.push(mapOnly);
}

// create a print template for each choice
templates = arrayUtils.map(templateNames, function (ch) {
var plate = new PrintTemplate();
plate.layout = plate.label = ch;
plate.format = "PDF";
plate.layoutOptions = {
"authorText": "Made by: ZZZ",
"copyrightText": "<copyright info here>",
"legendLayers": [],
"titleText": "<Test Title Here>",
"scalebarUnit": "Miles"
};
return plate;
});

// create the print dijit
app.printer = new Print({
"map": app.map,
"templates": templates,
url: app.printUrl
}, dom.byId("print_button"));
app.printer.startup();
}
function handleError(err) {
console.log("Something broke: ", err);
}

How I configure PrintTask not to use proxy?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Piterson,

   It sounds like you just need to configure your proxy url properly or just comment out those lines

esriConfig.defaults.io.proxyUrl = "/proxy/"; - HERE WE MUST PUT CORRECT ADDRESS

esriConfig.defaults.io.alwaysUseProxy = false;

The proxy should only be used when the text limit for the url params has been exceeded or you have that specific url setup in your proxy.config.

0 Kudos
PitersonPaulgek
New Contributor III

Robert,

I commented out

esriConfig.defaults.io.proxyUrl = "/proxy/"; - HERE WE MUST PUT CORRECT ADDRESS

esriConfig.defaults.io.alwaysUseProxy = false;

and now have an error

esri.config.defaults.io.proxyUrl is not set. If making a request to a CORS enabled server, please push the domain into esri.config.defaults.io.corsEnabledServers.
EsriVisualisation.js:576 Something broke: Error: esri.config.defaults.io.proxyUrl is not set. If making a request to a CORS enabled server, please push the domain into esri.config.defaults.io.corsEnabledServers.
at Object.c.getProxyUrl (https://js.arcgis.com/3.17/init.js:701:63)
at u (https://js.arcgis.com/3.17/init.js:859:368)
at e (https://js.arcgis.com/3.17/init.js:864:490)
at z (https://js.arcgis.com/3.17/init.js:871:60)
at initialiseMap (http://localhost:55549/Scripts/EsriVisualisation.js:526:25)
at initApp (http://localhost:55549/Scripts/EsriVisualisation.js:195:9)
at http://localhost:55549/Scripts/EsriVisualisation.js:186:5
at ia (https://js.arcgis.com/3.17/init.js:28:3)
at https://js.arcgis.com/3.17/init.js:28:256
at ja (https://js.arcgis.com/3.17/init.js:28:125)

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Piterson,

   So as the error message is saying you are attempting to connect to a server that is not the one the app is running on so you need to have the server you are contacting be CORS enabled and add that server to the esri.config.defaults.io.corsEnabledServers or you need to get your proxy configured properly to by-pass the need for CORS.

0 Kudos
PitersonPaulgek
New Contributor III

Robert,

Thank you. Could you provide more details how to 

1) check "server you are contacting be CORS enabled"

2) and add that server to the esri.config.defaults.io.corsEnabledServers.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

It is 10 times easier to setup the proxy then to enable CORS on your server.

PitersonPaulgek
New Contributor III

Should I 

esri.config.defaults.io.corsEnabledServers.push("?????server.com");

?

if yes, what I do for local environment?

esri.config.defaults.io.corsEnabledServers.push("localhost:55549");

??

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Piterson,

   Normally you would not have to add the machine that is running the app to the corsEnabledServers. It is the other servers (any other url you are using in your code). Is your web server the same machine as your ArcGIS Server?

0 Kudos