Search code examples
node.jsexpresspolymer

Not able to call my express backend middleware application using Polymer iron ajax


I am new to polymer and express and i have started building an application i am using polymer as front end and express as the backend which is acting as middleware for security , i am making iron ajax calls on various events a sample ajax call is

   <iron-ajax
   id="ajax"
 url="https://web-ui-hello.run.aws-usw02-pr.ice.predix.io/web/ui/api/getMapData"
 params='{"type":"all"}'
 handle-as="json"
 content-type="application/json"
 method="GET"
 on-response="helloResponse"
 debounce-duration="3000">

this ajax call is hitting my microservice in the backend but when i check in the express that i am only using as a middleware for adding some security token, i could not find this api hitting my express my app.js of this api is

 app.get ('/web/ui/api/getMapData',function(req,res){
 console.log('inside map');
  });

Can anyone help in this , i am stuck on this trying to figure out why it's not hitting express?


Solution

  • As far as I understand, your Express app being a middleware needs to manipulate the request/response sent to predix.

    So, instead of your web client, directly, calling the predix API, alter your client code to make request to your own server. Alter request, if any, and then initiate a new request from server to predix. Get the response of this new request, and alter it, if any. This new response should be sent as response of your original request from web client.

    WebClient ----(req1)-->ExpressServer ---(req2)--->Predix

    WebClient <---(res1)---ExpressServer <--(res2)----Predix