How to route the request to different target url in edge micro gateway

karlapudiravi
Participant III

Hi All,

My use case is to route the request to different targets based on the queryparams in edge micro gateway.

Please suggest..

Regards,

Ravi K.

0 4 576
4 REPLIES 4

Former Community Member
Not applicable

For version 2.3.1 and above in a custom plugin, overwrite the variable "req.targetPath" and/or "req.targetHostname".

For version 2.1.2: the variable is "req.reqUrl.pathname"

You may want to consider adding your logic in onrequest

Thanks @Srinandan Sridhar,

i am able to override the host with "req.targetHostname".

can you also please let me know how to update the port number for the target host as well.

Former Community Member
Not applicable

I suspect you will need to set the host name in the form "localhost:8080"

i tried it with "localhost:8060", but it is trying to connect on port 80, getting the below:

{"message":"getaddrinfo ENOTFOUND localhost:8060 localhost:8060:80","code":"ENOTFOUND","errno":"ENOTFOUND","syscall":"getaddrinfo","hostname":"localhost:8060","host":"localhost:8060","port":80}