Is it possible to add extra headers to the JavaScript client? We having a client with their ArcGIS server located in their DMZ where they could open it up if I could add extra headers to the http requests that goes from the JavaScript application (running in Azure).
it works on all requests made internally in the API. You specify which URL requests you want to intercept and then you can add the extra headers.
Something like adding headers might look like this.
<SPAN class="keyword token">var</SPAN> host <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fdomain-for-tiles.com" target="_blank">https://domain-for-tiles.com</A><SPAN>"</SPAN></SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> url <SPAN class="operator token">=</SPAN> <SPAN class="string token">"domain-for-tiles.com/the-tile-url"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> access_token <SPAN class="operator token">=</SPAN> <SPAN class="string token">"I&AM&A&TOKEN&&&&&"</SPAN> esriConfig<SPAN class="punctuation token">.</SPAN>request<SPAN class="punctuation token">.</SPAN>interceptors<SPAN class="punctuation token">.</SPAN><SPAN class="token function">push</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN> urls<SPAN class="punctuation token">:</SPAN> host<SPAN class="punctuation token">,</SPAN> before<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>params<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>params<SPAN class="punctuation token">.</SPAN>url<SPAN class="punctuation token">.</SPAN><SPAN class="token function">includes</SPAN><SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> params<SPAN class="punctuation token">.</SPAN>requestOptions<SPAN class="punctuation token">.</SPAN>headers <SPAN class="operator token">=</SPAN> params<SPAN class="punctuation token">.</SPAN>requestOptions<SPAN class="punctuation token">.</SPAN>headers <SPAN class="operator token">||</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN> params<SPAN class="punctuation token">.</SPAN>requestOptions<SPAN class="punctuation token">.</SPAN>headers<SPAN class="punctuation token">.</SPAN>ACCESS_TOKEN <SPAN class="operator token">=</SPAN> access_token<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I haven't added headers, but I've added access tokens via query params. You can add anything that is part of request options.
As I understand the documentation you could use RequestInterceptor for esriRequest, but how do I tie this to TileLayer?
var sampleLayer = new TileLayer({ url: "https://tiles.arcgis.com/tiles/nGt4QxSblgDfeJn9/arcgis/rest/services/New_York_Housing_Density/MapServer" });
var map = new Map({ basemap: "streets", layers: [sampleLayer] });
var view = new MapView({ container: "viewDiv", map: map, zoom: 4, center: [15, 65] // longitude, latitude });
If sampleLayer were on a server requiring extra headers, for instance a set "apitoken", is that possible?
Take a look at the RequestInterceptor in 4x. It should allow you do this on a URL basis.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.