Skip to content

Commit

Permalink
Merge pull request #5 from BrianEmilius/sanitize-paths
Browse files Browse the repository at this point in the history
Sanitize paths
  • Loading branch information
BrianEmilius committed Nov 27, 2018
2 parents 323f405 + f1ea739 commit 0821421
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Sanitize paths to prevent saving logs in dangerous places.
* Support for deeper log paths (currently, the log path can only be one directory deep).

## [2.0.0] - 2018-11-27
### Changed
* `logErrors` parameter list has been changed. You can now only define a name for the log file. See documentation.

### Removed
* Options parameter: You can no longer define options for logErrors in an object literal. Instead, use `logname`. See documentation.

## [1.1.1] - 2018-11-27
### Added
* Secret easter-egg
Expand Down
13 changes: 5 additions & 8 deletions lib/log-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ exports = module.exports = logErrors;

/**
*
* @param {Object} options
* @param {String} logName
* @return {Function}
* @api public
*/

function logErrors(options = {
'path': './logs',
'logName': 'errors.log'
}) {
if (!fs.existsSync(options.path))
fs.mkdirSync(options.path);
function logErrors(logName = 'express-errors.log') {
if (!fs.existsSync('./logs'))
fs.mkdirSync('./logs');
return function (err, req, res, next) {
if (err) {
const fullPath = path.join(options.path, options.logName);
const fullPath = path.join('.', 'logs', logName);
if (!fs.existsSync(fullPath))
fs.writeFileSync(fullPath, '');
const oldLog = fs.readFileSync(fullPath);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-log-errors",
"version": "1.1.1",
"version": "2.0.0",
"description": "express middleware for logging errors from routes",
"keywords": [
"expressjs",
Expand Down

0 comments on commit 0821421

Please sign in to comment.