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 static = require("serve-static");
|
||||||
var morgan = require("morgan");
|
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
|
* 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
|
* Initializes webserver callbacks
|
||||||
*/
|
*/
|
||||||
init: function (app) {
|
init: function (app) {
|
||||||
|
app.use(function (req, res, next) {
|
||||||
|
req.ip = ipForRequest(req);
|
||||||
|
next();
|
||||||
|
});
|
||||||
app.use(bodyParser.urlencoded({ extended: false }));
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(morgan(LOG_FORMAT, {
|
app.use(morgan("combined", {
|
||||||
stream: require("fs").createWriteStream(path.join(__dirname, "..", "..",
|
stream: require("fs").createWriteStream(path.join(__dirname, "..", "..",
|
||||||
"http.log"), {
|
"http.log"), {
|
||||||
flags: "a",
|
flags: "a",
|
||||||
|
|
Loading…
Reference in a new issue