Skip to content

Commit

Permalink
lint 🎗 ..
Browse files Browse the repository at this point in the history
  • Loading branch information
3imed-jaberi committed Jul 14, 2020
1 parent 59b5f51 commit 8aa484b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ If you are seeking permission to use these trademarks, then please [contact us](
[MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com/)
##
##
<a href="#"><img src="media/cabin-footer.png" alt="#" /></a>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@
"config.js"
]
}
}
}
32 changes: 15 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@ const middleware = require('./middleware');

class Cabin {
constructor(config) {
this.config = Object.assign(
{
key: '',
capture: null,
axe: {},
logger: null,
meta: {},
// <https://github.com/niftylettuce/parse-request>
parseRequest: {},
// <https://github.com/niftylettuce/parse-err>
errorProps: [],
// function that accepts (level, req, res) and returns a string
// (this is consumed by the cabin middleware and not available in browsers)
message
},
config
);
this.config = {
key: '',
capture: null,
axe: {},
logger: null,
meta: {},
// <https://github.com/niftylettuce/parse-request>
parseRequest: {},
// <https://github.com/niftylettuce/parse-err>
errorProps: [],
// function that accepts (level, req, res) and returns a string
// (this is consumed by the cabin middleware and not available in browsers)
message,
...config
};

// override key with root key in case user forgot
if (!isEmpty(this.config.axe) && this.config.key)
Expand Down
9 changes: 6 additions & 3 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ module.exports = function(...args) {
let level = 'info';
if (res.statusCode >= 500) level = 'error';
else if (res.statusCode >= 400) level = 'warn';
const message = this.config.message(
Object.assign({ level, req, res }, isExpress ? {} : { ctx: args[0] })
);
const message = this.config.message({
level,
req,
res,
...(isExpress ? {} : { ctx: args[0] })
});
if (err) logger[level](message, { err });
else logger[level](message);
});
Expand Down

0 comments on commit 8aa484b

Please sign in to comment.