TreeGateway / tree-gateway

This is a full featured and free API Gateway
http://treegateway.com
MIT License
189 stars 42 forks source link

access connection data from ProxyRequest Object #159

Closed pauloFernandes closed 6 years ago

pauloFernandes commented 6 years ago

I was trying to write a request interceptor that would get client's IP via req.connection.remoteAddress and store it for usage from my services.

When I tried to use the req.connection, I found that the req object accessible in the interceptors doesn't have this data. Is there another way to get connection data in interceptors, or is it possible to add this data in the ProxyRequest object?

I searched for it and looks like this object is mounted here. Maybe, the connection data could be sent to interceptors via

const proxyReq = (req as any).proxyReq || {
    body: req.body,
    headers: Object.assign({}, req.headers),
    method: req.method,
    url: req.url,
    user: req.user,
    connection: req.connection // Adding this field connection data from express req would be accessible in middleware req
};

Regards

pauloFernandes commented 6 years ago

Is this modification already published in npm? It still in 3.1.4 there

thiagobustamante commented 6 years ago

It is published now.