@tinyhttp/app
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -40,3 +40,3 @@ import { Server } from 'node:http'; | ||
applyExtensions: (req: Request, res: Response, next: NextFunction) => void; | ||
attach: (req: Req, res: Res) => void; | ||
attach: (req: Req, res: Res, next?: NextFunction) => void; | ||
cache: Record<string, unknown>; | ||
@@ -84,3 +84,3 @@ constructor(options?: AppConstructor<Req, Res>); | ||
* Render a template | ||
* @param file What to render | ||
* @param name What to render | ||
* @param data data that is passed to a template | ||
@@ -97,2 +97,3 @@ * @param options Template engine options | ||
* @param res Res object | ||
* @param next 'Next' function | ||
*/ | ||
@@ -103,3 +104,3 @@ handler<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions>(req: Req, res: Res, next?: NextFunction): void; | ||
* @param port server listening port | ||
* @param Server callback after server starts listening | ||
* @param cb callback to be invoked after server starts listening | ||
* @param host server listening host | ||
@@ -106,0 +107,0 @@ */ |
@@ -185,3 +185,4 @@ import { STATUS_CODES, createServer } from "node:http"; | ||
this.applyExtensions = options == null ? void 0 : options.applyExtensions; | ||
this.attach = (req, res) => setImmediate(this.handler.bind(this, req, res, void 0), req, res); | ||
const boundHandler = this.handler.bind(this); | ||
this.attach = (req, res, next) => setImmediate(boundHandler, req, res, next); | ||
this.cache = {}; | ||
@@ -245,3 +246,3 @@ } | ||
* Render a template | ||
* @param file What to render | ||
* @param name What to render | ||
* @param data data that is passed to a template | ||
@@ -360,2 +361,3 @@ * @param options Template engine options | ||
* @param res Res object | ||
* @param next 'Next' function | ||
*/ | ||
@@ -390,7 +392,9 @@ handler(req, res, next) { | ||
} | ||
mw.push({ | ||
handler: this.noMatchHandler, | ||
type: "mw", | ||
path: "/" | ||
}); | ||
if (this.parent == null) { | ||
mw.push({ | ||
handler: this.noMatchHandler, | ||
type: "mw", | ||
path: "/" | ||
}); | ||
} | ||
const handle = (mw2) => async (req2, res2, next2) => { | ||
@@ -426,4 +430,15 @@ var _a; | ||
let idx = 0; | ||
const loop = () => res.writableEnded || idx < mw.length && handle(mw[idx++])(req, res, next); | ||
next = next || ((err) => err ? this.onError(err, req, res) : loop()); | ||
const loop = () => void handle(mw[idx++])(req, res, next); | ||
const parentNext = next; | ||
next = (err) => { | ||
if (err != null) { | ||
return this.onError(err, req, res); | ||
} | ||
if (res.writableEnded) return; | ||
if (idx >= mw.length) { | ||
if (parentNext != null) parentNext(); | ||
return; | ||
} | ||
loop(); | ||
}; | ||
loop(); | ||
@@ -434,3 +449,3 @@ } | ||
* @param port server listening port | ||
* @param Server callback after server starts listening | ||
* @param cb callback to be invoked after server starts listening | ||
* @param host server listening host | ||
@@ -437,0 +452,0 @@ */ |
{ | ||
"name": "@tinyhttp/app", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "0-legacy, tiny & fast web framework as a replacement of Express", | ||
@@ -38,6 +38,6 @@ "type": "module", | ||
"@tinyhttp/cookie": "2.1.1", | ||
"@tinyhttp/proxy-addr": "2.2.0", | ||
"@tinyhttp/req": "2.2.3", | ||
"@tinyhttp/res": "2.2.3", | ||
"@tinyhttp/router": "2.2.2", | ||
"@tinyhttp/req": "2.2.3", | ||
"@tinyhttp/proxy-addr": "2.2.0" | ||
"@tinyhttp/router": "2.2.2" | ||
}, | ||
@@ -44,0 +44,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
78110
761