i am trying to retrieve the ip address from request using a custom middleware , but i am not able to retrieve it as there is no header coming like remote address through the request, please help me to fix this as i am new to tyk, i will share the middleware details below
var myMiddleware = new TykJS.TykMiddleware.NewMiddleware({});
myMiddleware.NewProcessRequest(function (request) {
var thisIP = request.remote_addr ? request.remote_addr : “unknown”;
// Set auth header
request.SetHeaders[“x-tyk-authorization”] = thisIP;
Then retrieve this request header in your custom middleware. You can use request.Headers["X-Remote-Addr"] in Javascript Middleware or you can refer to this other community post to use it in Python middleware.
Note: - Make sure you set enable_context_vars to true in your API definition. - Context Variables can only be used in 3 Middleware plugins : URL Rewriter, Modify Headers and Body Transforms.
Hello, you can also use the X-Forwarded-For header to identify the client’s IP address. This is only valid if Nginx or another load balancer/firewall ensures that the IP address is overwritten with the client’s IP.