Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove sockets.reqFromSocket
- Loading branch information
1 parent
8fd3c04
commit bc880ee
Showing
7 changed files
with
41 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const url = require('url'); | ||
|
||
// creates a slimmed down version of the request object | ||
exports.buildReqObject = (req, payload) => { | ||
req = req || {}; | ||
const headers = req.headers || {}; | ||
const encrypted = req.connection ? !!req.connection.encrypted : false; | ||
let host = headers.host; | ||
const referer = headers.referer || ''; | ||
|
||
if (!host) { | ||
host = url.parse(referer).host || ''; | ||
} | ||
|
||
return { | ||
uid: req.uid, | ||
params: req.params, | ||
method: req.method, | ||
body: payload || req.body, | ||
ip: req.ip, | ||
host: host, | ||
protocol: encrypted ? 'https' : 'http', | ||
secure: encrypted, | ||
url: referer, | ||
path: referer.substr(referer.indexOf(host) + host.length), | ||
headers: headers, | ||
}; | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
bc880ee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍