@tinyhttp/app 2.0.23 → 2.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -2
- package/dist/onError.d.ts +2 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -46,7 +46,9 @@ const getSubdomains = (req, subdomainOffset = 2) => {
|
|
|
46
46
|
const subdomains = isIP(hostname) ? [hostname] : hostname.split(".").reverse();
|
|
47
47
|
return subdomains.slice(subdomainOffset);
|
|
48
48
|
};
|
|
49
|
-
const onErrorHandler = (err, _req, res)
|
|
49
|
+
const onErrorHandler = function(err, _req, res) {
|
|
50
|
+
if (this.onError === onErrorHandler && this.parent)
|
|
51
|
+
return this.parent.onError(err, _req, res);
|
|
50
52
|
if (!process.env.TESTING && err instanceof Error)
|
|
51
53
|
console.error(err);
|
|
52
54
|
const code = err.code in STATUS_CODES ? err.code : err.status;
|
|
@@ -136,7 +138,7 @@ class App extends Router {
|
|
|
136
138
|
this.locals = {};
|
|
137
139
|
this.engines = {};
|
|
138
140
|
this.onError = (options == null ? void 0 : options.onError) || onErrorHandler;
|
|
139
|
-
this.noMatchHandler = (options == null ? void 0 : options.noMatchHandler) || this.onError.bind(
|
|
141
|
+
this.noMatchHandler = (options == null ? void 0 : options.noMatchHandler) || this.onError.bind(this, { code: 404 });
|
|
140
142
|
this.settings = options.settings || { xPoweredBy: true, views: process.cwd() };
|
|
141
143
|
this.applyExtensions = options == null ? void 0 : options.applyExtensions;
|
|
142
144
|
this.attach = (req, res) => setImmediate(this.handler.bind(this, req, res, void 0), req, res);
|
package/dist/onError.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NextFunction } from '@tinyhttp/router';
|
|
2
2
|
import type { Request } from './request.js';
|
|
3
3
|
import type { Response } from './response.js';
|
|
4
|
-
|
|
4
|
+
import type { App } from './app';
|
|
5
|
+
export declare type ErrorHandler = (this: App, err: any, req: Request, res: Response, next?: NextFunction) => void;
|
|
5
6
|
export declare const onErrorHandler: ErrorHandler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinyhttp/app",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.25",
|
|
4
4
|
"description": "0-legacy, tiny & fast web framework as a replacement of Express",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://tinyhttp.v1rtl.site",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@tinyhttp/cookie": "2.0.5",
|
|
36
36
|
"@tinyhttp/proxy-addr": "2.0.5",
|
|
37
37
|
"@tinyhttp/req": "2.0.14",
|
|
38
|
-
"@tinyhttp/res": "2.0.
|
|
38
|
+
"@tinyhttp/res": "2.0.19",
|
|
39
39
|
"@tinyhttp/router": "2.0.6",
|
|
40
40
|
"header-range-parser": "1.1.3",
|
|
41
41
|
"regexparam": "^2.0.1"
|