Created
October 25, 2017 00:32
-
-
Save evanshortiss/2fc348fa70297595c4430c3b0da8346f to your computer and use it in GitHub Desktop.
Simple middleware to log information related to the underlying socket and proxies that forwarded the incoming request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Set a DEBUG environment var to "*" or "socket-logger" to enable | |
| const log = require('debug')('socket-logger') | |
| // Place this before other middlewares so it is invoked first - remember they invoke in the defined order | |
| app.use(function (req, res, next) { | |
| log('============================================================') | |
| log(`received request from remote socket with req.headers - ${JSON.stringify(req.headers)}`) | |
| log(`received request from remote socket with req.socket.address - ${JSON.stringify(req.socket.address())}`) | |
| log(`received request from remote socket with req.socket.localAddress - ${req.socket.localAddress}`) | |
| log(`received request from remote socket with req.socket.localPort - ${req.socket.localPort}`) | |
| log(`received request from remote socket with req.socket.remoteFamily - ${req.socket.remoteFamily}`) | |
| log(`received request from remote socket with req.socket.remotePort - ${req.socket.remotePort}`) | |
| log(`received request from remote socket with req.socket.remoteAddress - ${req.socket.remoteAddress}`) | |
| log('============================================================') | |
| // carry on with request processing... | |
| next() | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment