Custom Plugin for Edgemicrogateway to update target.url dynamically

I have a edgemicro_proxy in edge UI, over there I am using target.url as "http://mocktarget.apigee.net/"

I also have a edgemicrogateway.

I want to update the target.url to 267.12.12.12 runtime via some plugin in edgemicro so how can I achieve this ? how to write plugin for this ? I am new to JS.

by looking at this past question  it seems only plugin will this job so can someone please help me in writing this plugin so that I will achieve this functionality.

I have seen this post -> https://docs.apigee.com/api-platform/microgateway/3.2.x/develop-custom-plugins but could not see much help related to target rewrite -> https://docs.apigee.com/api-platform/microgateway/3.2.x/develop-custom-plugins#rewritingtargeturlsin...

0 2 165
2 REPLIES 2

Ha, I think ... I misunderstood your prior message. 

Now I understand a key fact that I was missing earlier: you are using Apigee Edge microgateway.

Writing policies that run within the API Proxy, including setting target.url in the target request flow, does not affect an API that you run through Edge microgateway .  In fact Edge microgateway ignores all policies that you configure in the Edge enterprise gateway. None of them have any effect. 

I am not an expert, but reading the documentation, it seems the onRequest method gives you access to the full request, including headers, url, query and so on. Can you modify the URL there? 

In fact there is a specific section in the doc page that discusses rewriting the target URL.  Have you tried what is written there?

According to my understanding of the documentation, it would be a plugin that looks something like this:

return {
      onrequest: function (req, res, next) {
        if (req.targetPath.includes(pathPrefix)) {
          req.targetHostname = newTargethost;
          req.targetPath = newUrl;
          req.targetPort = 80;
        }
        next();
      }
};

 

@dchiesa1 

 

 

return {
      onrequest: function (req, res, next) {
        if (req.targetPath.includes(pathPrefix)) {
          req.targetHostname = newTargethost;
          req.targetPath = newUrl;
          req.targetPort = 80;
        }
        next();
      }
};

 


1. ok so is there any readymade plugin available to achieve this behaviour for edgemicrogateway ? because writing plugin for this is not possible for me since I don't have knowledge on JS.

2. And also will it really update target.url in edge micro proxy(this proxy is being connected to edgemicrogateway) since I was also not able to update target.url dynamically in edge proxy even though I had target-rewrite policy in target endpoint flow.