Skip to content

Instantly share code, notes, and snippets.

@OrionStark
Last active February 11, 2020 03:10
Show Gist options
  • Save OrionStark/6b466c1f140c7e7b327557dd73c88348 to your computer and use it in GitHub Desktop.
Save OrionStark/6b466c1f140c7e7b327557dd73c88348 to your computer and use it in GitHub Desktop.
function __grabRequest(req) {
// We need the consume IP Address for collecting a log for our Gateway
const ipAddress = (req.headers['x-forwarded-for'] || '').split(',').pop() ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress
const apiSignatureKey = req.headers['basic_auth'] || '' // Basic Auth for consumer.
return {
ip_address: ipAddress,
basic_auth: apiSignatureKey,
host: req.headers['host'], // Optional
user_agent: req.headers['user-agent'] || '', // Optional
method: req.method,
path: req.path,
originalUrl: req.originalUrl,
query: req.query, // We keep the query request to be forward to the service
params: req.params, // We also keep the params to be forwarded
app_id: req.headers['app_id'], // This header for specifying which service will be used
body: req.body,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment