mirror of https://github.com/calzoneman/sync.git
Fix IP address race condition for logging
This commit is contained in:
parent
2b60ab8e10
commit
2ea9dbcb75
|
@ -14,9 +14,6 @@ var cookieParser = require("cookie-parser");
|
|||
var static = require("serve-static");
|
||||
var morgan = require("morgan");
|
||||
|
||||
const LOG_FORMAT = ':real-address - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"'
|
||||
morgan.token("real-address", ipForRequest);
|
||||
|
||||
/**
|
||||
* Extracts an IP address from a request. Uses X-Forwarded-For if the IP is localhost
|
||||
*/
|
||||
|
@ -204,9 +201,13 @@ module.exports = {
|
|||
* Initializes webserver callbacks
|
||||
*/
|
||||
init: function (app) {
|
||||
app.use(function (req, res, next) {
|
||||
req.ip = ipForRequest(req);
|
||||
next();
|
||||
});
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
app.use(cookieParser());
|
||||
app.use(morgan(LOG_FORMAT, {
|
||||
app.use(morgan("combined", {
|
||||
stream: require("fs").createWriteStream(path.join(__dirname, "..", "..",
|
||||
"http.log"), {
|
||||
flags: "a",
|
||||
|
|
Loading…
Reference in New Issue