@tinyhttp/app 2.0.24 → 2.0.26
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 +12 -5
- 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;
|
|
@@ -130,13 +132,18 @@ const applyHandler = (h) => async (req, res, next) => {
|
|
|
130
132
|
}
|
|
131
133
|
};
|
|
132
134
|
class App extends Router {
|
|
135
|
+
middleware = [];
|
|
136
|
+
locals = {};
|
|
137
|
+
noMatchHandler;
|
|
138
|
+
onError;
|
|
139
|
+
settings;
|
|
140
|
+
engines = {};
|
|
141
|
+
applyExtensions;
|
|
142
|
+
attach;
|
|
133
143
|
constructor(options = {}) {
|
|
134
144
|
super();
|
|
135
|
-
this.middleware = [];
|
|
136
|
-
this.locals = {};
|
|
137
|
-
this.engines = {};
|
|
138
145
|
this.onError = (options == null ? void 0 : options.onError) || onErrorHandler;
|
|
139
|
-
this.noMatchHandler = (options == null ? void 0 : options.noMatchHandler) || this.onError.bind(
|
|
146
|
+
this.noMatchHandler = (options == null ? void 0 : options.noMatchHandler) || this.onError.bind(this, { code: 404 });
|
|
140
147
|
this.settings = options.settings || { xPoweredBy: true, views: process.cwd() };
|
|
141
148
|
this.applyExtensions = options == null ? void 0 : options.applyExtensions;
|
|
142
149
|
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.js';
|
|
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.26",
|
|
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.20",
|
|
39
39
|
"@tinyhttp/router": "2.0.6",
|
|
40
40
|
"header-range-parser": "1.1.3",
|
|
41
41
|
"regexparam": "^2.0.1"
|