Esri-arcgis request intercept based on wildcard route

12-02-2020 04:24 AM
New Contributor

I'm trying to implement a MapLayer in my react application. The map is only accessible over a proxy which needs authentication to identify the users for each end every request.

To provide the token i added the following request interceptor to make sure all calls which access that backend would be expanded by the authorization. If i do it this way there is no header added to the requests.




  urls: ['backend/api/*'],
  before: async function (params: any) {
    params.requestOptions.headers = {
      Authorization: 'Bearer ' + token),





If i remove the urls parameter so that all routes are extended with the token I'll recieve some cors errors because the esri package also makes some calls to another api where i get blocked because i'm sending an authorization header which is not expected.

Other api:

How can i make sure only requests to my api will be extended with the autorization header?

0 Kudos
1 Reply
Frequent Contributor II

Can you try changing it to a regex, like this

  urls: [/\/backend\/api\//],

 I don't think you even need the wildcard, but if you used the full domain, like "https://myserver/backend/api" it should get recognized. We don't parse for wildcards, but will check if the request url starts with a string or test a regex you provide.