Skip to content
Permalink
Browse files

Allow request matching across nginx and node

  • Loading branch information
davidmerfield committed Oct 13, 2019
1 parent 6ef2be9 commit 99c321df444026335e5922bc9516231cbf83eec3
Showing with 52 additions and 1 deletion.
  1. +50 −0 app/index.js
  2. +1 −1 config/nginx/http.conf
  3. +1 −0 config/nginx/reverse-proxy.conf
@@ -24,6 +24,56 @@ Blot.set("trust proxy", "loopback");
// Prevent <iframes> embedding pages served by Blot
Blot.use(helmet.frameguard("allow-from", config.host));

Blot.use(function(req, res, next){
var init = Date.now();

console.log('[' + clfdate(new Date()) +']', req.headers['x-request-id'], req.protocol + '://' + req.host + req.originalUrl);

res.on('finish', function(){
console.log('[' + clfdate(new Date())+']', req.headers['x-request-id'], res.statusCode, Date.now() - init + 'ms', req.protocol + '://' + req.host + req.originalUrl);
});

next();
});

var CLF_MONTH = [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
];

function pad2 (num) {
var str = String(num)

return (str.length === 1 ? '0' : '') + str
}

function rpad3 (num) {
var str = String(num)

if (str.length === 2)
return str + '0';

if (str.length === 1)
return str + '00';

return str;
}

function clfdate (dateTime) {
var date = dateTime.getUTCDate()
var hour = dateTime.getUTCHours()
var mins = dateTime.getUTCMinutes()
var secs = dateTime.getUTCSeconds()
var year = dateTime.getUTCFullYear()
var msecs = dateTime.getUTCMilliseconds();

var month = CLF_MONTH[dateTime.getUTCMonth()]

return pad2(date) + '/' + month + '/' + year +
':' + pad2(hour) + ':' + pad2(mins) + ':' + pad2(secs) + '.' + rpad3(msecs)
' +0000'
}

// Blot is composed of four sub applications.

// The CDN
@@ -1,4 +1,4 @@
log_format test '[$time_local] $status $request_time $upstream_response_time $server_name $scheme://$host$request_uri';
log_format test '[$time_local] $request_id $status $request_time $upstream_response_time $server_name $scheme://$host$request_uri';

error_log /var/www/blot/logs/nginx.log warn;

@@ -5,6 +5,7 @@ proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Request-ID $request_id;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';

0 comments on commit 99c321d

Please sign in to comment.
You can’t perform that action at this time.