@ceicc/range
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
29
index.js
@@ -54,2 +54,8 @@ const | ||
* @property {boolean} [hushErrors] Whether to ignore errors and reply with status code `500`, or pass the error to `next` function - default: `false` | ||
* | ||
* @property {boolean} [trailingSlash] Redirect directory requests to add trailing slash - default `true` | ||
* | ||
* disabling this option will led to relative path issues. [see #9](https://github.com/Ceicc/range/issues/9) | ||
* | ||
* `implicitIndex` must be `true` | ||
*/ | ||
@@ -67,3 +73,3 @@ | ||
baseDir: { default: '.', type: "string" }, | ||
hushErrors: { default: false, type: "boolean" }, | ||
hushErrors: { default: false, type: "boolean" }, | ||
conditional: { default: true, type: "boolean" }, | ||
@@ -76,5 +82,11 @@ range: { default: true, type: "boolean" }, | ||
implicitIndex: { default: true, type: "boolean|array" }, | ||
trailingSlash: { default: true, type: "boolean" }, | ||
}) | ||
/** | ||
* @param {IncomingMessage} req request object | ||
* @param {ServerResponse} res response object | ||
* @param {Function} next errors handler function | ||
*/ | ||
return async function rangeMiddleware(req, res, next = console.error) { | ||
@@ -128,2 +140,9 @@ | ||
if (options.trailingSlash && !hasTrailingSlash(req.pathname)) { | ||
res.statusCode = 301 | ||
res.setHeader("Location", req.pathname + "/") | ||
res.end() | ||
return | ||
} | ||
const extensions = new Set() | ||
@@ -301,2 +320,10 @@ | ||
return streamIt(path, res, { start, end }) | ||
} | ||
/** | ||
* @param {string} url | ||
* @returns {boolean} | ||
*/ | ||
function hasTrailingSlash(url) { | ||
return url[url.length - 1] === "/" | ||
} |
{ | ||
"name": "@ceicc/range", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"description": "http range request handler", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,3 +23,3 @@ # range | ||
``` | ||
This will server every request starts with `/public/` with `range`. | ||
This will serve every request starts with `/public/` with `range`. | ||
@@ -107,3 +107,14 @@ The base directory will be `.` or the current working directory, unless specified in the `options` object. | ||
#### `trailingSlash` | ||
- default: `true` | ||
- type: `boolean` | ||
Redirect directory requests to add trailing slash - default `true` | ||
disabling this option will led to relative path issues. [see #9](https://github.com/Ceicc/range/issues/9) | ||
`implicitIndex` must be `true` | ||
## Real World Example | ||
@@ -110,0 +121,0 @@ |
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
13722
236
134
1