Skip to content

Commit

Permalink
Fixing identification of 'req.exit' and renaming it from 'req.last' w…
Browse files Browse the repository at this point in the history
…hich is incorrect behavior
  • Loading branch information
avoidwork committed Aug 28, 2024
1 parent 3857232 commit a6e0bfd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ Executes after the response has been sent.
## Helpers
`req` & `res` are decorated with helper functions to simplify responding.

### req.exit(req, res, next)
Exit middleware of the route for the HTTP method as a way to "skip" authentication middleware for unprotected routes.

### res.error(status[, body, headers])
Sends an error response.

Expand All @@ -236,9 +239,6 @@ Shorthand of `res.setHeader()`.
### res.json(body, [status = 200, headers])
Sends a JSON response.

### res.last(req, res, next)
Last middleware of the route for the HTTP method as a way to "skip" to the middleware which sends a response.

### res.redirect(uri[, perm = false])
Sends a redirection response.

Expand Down
2 changes: 1 addition & 1 deletion dist/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 19.0.2
* @version 20.0.0
*/
'use strict';

Expand Down
12 changes: 6 additions & 6 deletions dist/woodland.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 19.0.2
* @version 20.0.0
*/
'use strict';

Expand Down Expand Up @@ -276,7 +276,7 @@ function pipeable (method, arg) {
return method !== HEAD && arg !== null && typeof arg.on === FUNCTION;
}

function reduce (uri, map = new Map(), arg = {}, end = false, ignore = new Set()) {
function reduce (uri, map = new Map(), arg = {}, end = false) {
Array.from(map.values()).filter(i => {
i.regex.lastIndex = INT_0;

Expand All @@ -285,8 +285,8 @@ function reduce (uri, map = new Map(), arg = {}, end = false, ignore = new Set()
for (const fn of i.handlers) {
arg.middleware.push(fn);

if (end && arg.last === null && ignore.has(fn) === false) {
arg.last = fn;
if (end && arg.exit === null) {
arg.exit = fn;
}
}

Expand Down Expand Up @@ -704,7 +704,7 @@ class Woodland extends node_events.EventEmitter {
params(req, result.getParams);
}

req.last = result.last;
req.exit = result.exit;
next(req, res, result.middleware[Symbol.iterator]())();
} else {
res.error(getStatus(req, res));
Expand All @@ -719,7 +719,7 @@ class Woodland extends node_events.EventEmitter {
if (cached !== void 0) {
result = cached;
} else {
result = {getParams: null, middleware: [], params: false, visible: INT_0, last: null};
result = {getParams: null, middleware: [], params: false, visible: INT_0, exit: null};
reduce(uri, this.middleware.get(WILDCARD), result);

if (method !== WILDCARD) {
Expand Down
12 changes: 6 additions & 6 deletions dist/woodland.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 19.0.2
* @version 20.0.0
*/
import {STATUS_CODES,METHODS}from'node:http';import {join,extname}from'node:path';import {EventEmitter}from'node:events';import {stat,readdir}from'node:fs/promises';import {etag}from'tiny-etag';import {precise}from'precise';import {lru}from'tiny-lru';import {createRequire}from'node:module';import {fileURLToPath,URL}from'node:url';import {readFileSync,createReadStream}from'node:fs';import {coerce}from'tiny-coerce';import mimeDb from'mime-db';const __dirname$1 = fileURLToPath(new URL(".", import.meta.url));
const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -258,7 +258,7 @@ function pipeable (method, arg) {
return method !== HEAD && arg !== null && typeof arg.on === FUNCTION;
}

function reduce (uri, map = new Map(), arg = {}, end = false, ignore = new Set()) {
function reduce (uri, map = new Map(), arg = {}, end = false) {
Array.from(map.values()).filter(i => {
i.regex.lastIndex = INT_0;

Expand All @@ -267,8 +267,8 @@ function reduce (uri, map = new Map(), arg = {}, end = false, ignore = new Set()
for (const fn of i.handlers) {
arg.middleware.push(fn);

if (end && arg.last === null && ignore.has(fn) === false) {
arg.last = fn;
if (end && arg.exit === null) {
arg.exit = fn;
}
}

Expand Down Expand Up @@ -684,7 +684,7 @@ function writeHead (res, headers = {}) {
params(req, result.getParams);
}

req.last = result.last;
req.exit = result.exit;
next(req, res, result.middleware[Symbol.iterator]())();
} else {
res.error(getStatus(req, res));
Expand All @@ -699,7 +699,7 @@ function writeHead (res, headers = {}) {
if (cached !== void 0) {
result = cached;
} else {
result = {getParams: null, middleware: [], params: false, visible: INT_0, last: null};
result = {getParams: null, middleware: [], params: false, visible: INT_0, exit: null};
reduce(uri, this.middleware.get(WILDCARD), result);

if (method !== WILDCARD) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "woodland",
"version": "19.0.2",
"version": "20.0.0",
"description": "Lightweight HTTP framework with automatic headers",
"type": "module",
"types": "types/woodland.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function pipeable (method, arg) {
return method !== HEAD && arg !== null && typeof arg.on === FUNCTION;
}

export function reduce (uri, map = new Map(), arg = {}, end = false, ignore = new Set()) {
export function reduce (uri, map = new Map(), arg = {}, end = false) {
Array.from(map.values()).filter(i => {
i.regex.lastIndex = INT_0;

Expand All @@ -172,8 +172,8 @@ export function reduce (uri, map = new Map(), arg = {}, end = false, ignore = ne
for (const fn of i.handlers) {
arg.middleware.push(fn);

if (end && arg.last === null && ignore.has(fn) === false) {
arg.last = fn;
if (end && arg.exit === null) {
arg.exit = fn;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/woodland.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ export class Woodland extends EventEmitter {
params(req, result.getParams);
}

req.last = result.last;
req.exit = result.exit;
next(req, res, result.middleware[Symbol.iterator]())();
} else {
res.error(getStatus(req, res));
Expand All @@ -480,7 +480,7 @@ export class Woodland extends EventEmitter {
if (cached !== void 0) {
result = cached;
} else {
result = {getParams: null, middleware: [], params: false, visible: INT_0, last: null};
result = {getParams: null, middleware: [], params: false, visible: INT_0, exit: null};
reduce(uri, this.middleware.get(WILDCARD), result);

if (method !== WILDCARD) {
Expand Down

0 comments on commit a6e0bfd

Please sign in to comment.