Skip to content

Commit

Permalink
Fixed some bugs, removed /metrics and /health from logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Phara0h committed Apr 7, 2021
1 parent daa977e commit 7b98a92
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 38 deletions.
4 changes: 2 additions & 2 deletions include/routes/v1/users.js
Expand Up @@ -364,7 +364,7 @@ function routes(app, opts, done) {
return group;
}

let user = await getUser(req, res);
var user = await getUser(req, res);

if (user && user.msg) {
res.code(400);
Expand All @@ -387,7 +387,7 @@ function routes(app, opts, done) {
return group;
}

const user = await getUser(req, res);
var user = await getUser(req, res);

if (user && user.msg) {
res.code(400);
Expand Down
79 changes: 45 additions & 34 deletions include/server/router.js
Expand Up @@ -7,6 +7,7 @@ const log = config.log.logger;
const regex = require('../utils/regex');
const parse = require('../utils/parse');
//const { proxy } = require('fast-proxy')({});
const ignored_log_routes = ['/' + config.serviceName + '/metrics', '/' + config.serviceName + '/health'];

class Router {
constructor(server) {
Expand Down Expand Up @@ -139,16 +140,27 @@ class Router {
req.headers['t-id'] = sessionUser.id;
req.headers['t-email'] = sessionUser.email;
req.headers['t-perm'] = r.name;
req.headers['t-ip'] = parse.getIp(req) || '0.0.0.0';
}

if (req.raw.url.indexOf('/' + config.serviceName + '/') == 0 && !r.host) {
if (config.log.requests) {
if (config.log.requests && ignored_log_routes.indexOf(req.raw.url) == -1) {
if (authenticated) {
log.info(
sessionUser.username + ' (' + routedGroup.name + ') | ' + req.raw.ip + ' | [' + req.raw.method + '] ' + req.raw.url
(sessionUser.username || sessionUser.email) +
' (' +
routedGroup.name +
') | ' +
parse.getIp(req) +
' | [' +
req.raw.method +
'] ' +
req.raw.url
);
} else {
log.info('Unregistered User' + ' (anonymous)' + ' | ' + req.raw.ip + ' | [' + req.raw.method + '] ' + req.raw.url);
log.info(
'Unregistered User' + ' (anonymous)' + ' | ' + parse.getIp(req) + ' | [' + req.raw.method + '] ' + req.raw.url
);
}
}
return false;
Expand All @@ -166,37 +178,36 @@ class Router {
if (r.remove_from_path) {
req.raw.url = req.raw.url.replace(this.transformRoute(sessionUser, r, r.remove_from_path, routedGroup), '');
}

if (config.log.requests && authenticated) {
log.info(
sessionUser.username +
' (' +
routedGroup.name +
') | ' +
parse.getIp(req) +
' | [' +
req.raw.method +
'] ' +
req.raw.url +
' -> ' +
target.target +
req.raw.url
);
}

if (config.log.requests && !authenticated) {
log.info(
'Unregistered User' +
' (anonymous)' +
' | ' +
parse.getIp(req) +
' | [' +
req.raw.method +
'] ' +
req.raw.url +
' -> ' +
target.target
);
if (config.log.requests && ignored_log_routes.indexOf(req.raw.url) == -1) {
if (authenticated) {
log.info(
(sessionUser.username || sessionUser.email) +
' (' +
routedGroup.name +
') | ' +
parse.getIp(req) +
' | [' +
req.raw.method +
'] ' +
req.raw.url +
' -> ' +
target.target +
req.raw.url
);
} else {
log.info(
'Unregistered User' +
' (anonymous)' +
' | ' +
parse.getIp(req) +
' | [' +
req.raw.method +
'] ' +
req.raw.url +
' -> ' +
target.target
);
}
}

if (r.host && req._wssocket) {
Expand Down
6 changes: 5 additions & 1 deletion package.json
Expand Up @@ -27,6 +27,10 @@
"gateway",
"api"
],
"bin": {
"travelling": "./index.js",
"traveling": "./index.js"
},
"author": "Jt Whissel",
"license": "MIT",
"bugs": {
Expand All @@ -42,7 +46,7 @@
"fastify": "^3.11.0",
"fastify-cookie": "^5.1.0",
"fastify-favicon": "^3.0.0",
"fastify-good-sessions": "^1.4.0",
"fastify-good-sessions": "^1.4.2",
"fastify-plugin": "^3.0.0",
"fastify-static": "^3.4.0",
"handlebars": "^4.7.3",
Expand Down
2 changes: 1 addition & 1 deletion sdk/package.json
@@ -1,6 +1,6 @@
{
"name": "travelling-sdk",
"version": "1.0.1",
"version": "1.1.0",
"description": "",
"main": "node/index.js",
"files": [
Expand Down

0 comments on commit 7b98a92

Please sign in to comment.