Microgateway custom plugin not working

danielhoenig
Participant III

I'm trying to learn how to add custom plugins to the microgateway and I'm having trouble getting mine to execute. I'm following this documentation and it's not working.

https://docs.apigee.com/api-platform/microgateway/2.5.x/develop-custom-plugins.html

I followed the instructions and when I send a request it acts like I never added my plugin - it returns my target endpoint payload. I expect it to return the response-override response of "Hello, World!". It's the only plugin in plugins:sequence section of my config file, so why would'nt it execute?

0 5 347
5 REPLIES 5

Hi @Daniel Hoenig

Any way to post more details here (config file)? Also, nothing in the microgateway logs?

Sorry, should have attached this on the original post.

danielhoenig-eval-test-configyaml.txt

Here's where the custom plugin is located - C:\Users\hoenigd\AppData\Roaming\npm\node_modules\edgemicro\node_modules\microgateway-plugins\response-override. In this directory I have an index.js file and packacge.json file.

This is all it writes to the logs

1551725137766 info sourceRequest m=GET, u=/prototype/people, h=localhost:8000, r=::1:64140, i=b3c2c060-3ead-11e9-b77e-ab922a93ca20
1551725137766 info targetRequest m=GET, u=/api/people, h=swapi.co:NaN, i=b3c2c060-3ead-11e9-b77e-ab922a93ca20
1551725138081 info targetResponse s=301, d=315, i=b3c2c060-3ead-11e9-b77e-ab922a93ca20
1551725138082 info sourceResponse s=301, d=316, i=b3c2c060-3ead-11e9-b77e-ab922a93ca20
<br>

So, it looks like it's running my custom plugin. I tested it by adding console.log() commands in the plugin event methods. But, for some reason it's not replacing the response data with "Hello, World!". If in my onend_response method I put "next(null, "Hello, World!");" should it overwrite what my target endpoint is returning?

ericschult
Participant II

Any clues in the debug(...) output?

Look for succss messages in starting your plugin

env DEBUG=* edgemicro start .....

(or however you enable an env var on windows)


you should see message like

gateway:init loading plugin from .../microgateway-plugins/response-override

551921263063 info installed plugin from response-override

or an error that should lead you to the problem.

-E

I verified the plugin is loading and executing, but it's not overwriting the response with "Hello World". In one case it returns the target endpoints payload, and another case it doesn't give a response at all. The only difference, that I can tell is the target endpoints are different.