Comparing version 0.7.0 to 0.8.0
# CHANGES to httpquery | ||
## 0.8.0 | ||
- feat: support `directory` and `passthroughErrors` | ||
- fix: indicate character may also be missing in error message | ||
## 0.7.0 | ||
@@ -4,0 +9,0 @@ |
@@ -27,6 +27,18 @@ import {readFileSync} from 'fs'; | ||
name: 'path', type: String, | ||
description: 'The path on top of `cwd`. Defaults to the empty string', | ||
description: 'The path on top of `cwd`. This will be used for ' + | ||
'comparisons with `directory`, Defaults to the empty string', | ||
typeLabel: '{underline PATH}' | ||
}, | ||
{ | ||
name: 'directory', type: String, | ||
description: 'Files not in this path (the `path` + `req.url`) will be ' + | ||
'passed on to `next`. Defaults to none', | ||
typeLabel: '{underline NAMESPACE}' | ||
}, | ||
{ | ||
name: 'passthroughErrors', type: Boolean, | ||
description: 'Whether to pass through errors with `next()`. Defaults to ' + | ||
'`false`' | ||
}, | ||
{ | ||
name: 'debug', alias: 'd', type: Boolean, | ||
@@ -33,0 +45,0 @@ description: 'Whether or not to show extra debugging details; not ' + |
@@ -27,3 +27,3 @@ // Todo: More middleware passing options besides jsonData; ensure can use | ||
const handleJsonata = ({ | ||
req, res, responseHeaders, fileContents, exitError, finish | ||
req, res, responseHeaders, fileContents, exitError, finish, next | ||
}) => { | ||
@@ -44,3 +44,3 @@ const jsonataExpression = jsonata( | ||
if (error) { | ||
exitError(res, responseHeaders, error.message); | ||
exitError(res, responseHeaders, error.message, next); | ||
return; | ||
@@ -135,4 +135,12 @@ } | ||
const debug = cfg.debug ?? false; | ||
const {directory, passthroughErrors} = cfg; | ||
const exitError = (res, responseHeaders, err) => { | ||
const exitError = (res, responseHeaders, err, next) => { | ||
if (passthroughErrors) { | ||
if (next) { | ||
next(err); | ||
return; | ||
} | ||
return; | ||
} | ||
const errorMessage = debug ? err : 'ERROR'; | ||
@@ -226,3 +234,8 @@ write( | ||
if (!(/\w/u).test(url[0]) || (/\.\./u).test(url)) { | ||
exitError(res, responseHeaders, 'Disallowed character in file name'); | ||
exitError( | ||
res, | ||
responseHeaders, | ||
'Disallowed or missing character in file name', | ||
next | ||
); | ||
return; | ||
@@ -235,5 +248,10 @@ } | ||
try { | ||
fileContents = await readFile(join(cwd, path, url)); | ||
const directoryFile = join(path, url); | ||
if (directory && directoryFile.startsWith(directory)) { | ||
next(); | ||
return; | ||
} | ||
fileContents = await readFile(join(cwd, directoryFile)); | ||
} catch (err) { | ||
exitError(res, responseHeaders, err.message); | ||
exitError(res, responseHeaders, err.message, next); | ||
return; | ||
@@ -262,3 +280,3 @@ } | ||
handleJsonata({ | ||
req, res, responseHeaders, fileContents, exitError, finish | ||
req, res, responseHeaders, fileContents, exitError, finish, next | ||
}); | ||
@@ -265,0 +283,0 @@ return; |
{ | ||
"name": "httpquery", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"author": "Brett Zamir", | ||
@@ -5,0 +5,0 @@ "contributors": [], |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
68543
379
1