@tinyhttp/app 2.2.3 → 2.3.0
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/app.d.ts +7 -8
- package/dist/app.d.ts.map +1 -1
- package/dist/extend.d.ts +4 -3
- package/dist/extend.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -78
- package/dist/index.js.map +1 -1
- package/dist/onError.d.ts +5 -4
- package/dist/onError.d.ts.map +1 -1
- package/dist/request.d.ts +12 -14
- package/dist/request.d.ts.map +1 -1
- package/dist/response.d.ts +5 -5
- package/dist/response.d.ts.map +1 -1
- package/dist/types.d.ts +8 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/view.d.ts +2 -9
- package/dist/view.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/app.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Server } from 'node:http';
|
|
3
|
-
import
|
|
4
|
-
import type { Response } from './response.js';
|
|
5
|
-
import type { ErrorHandler } from './onError.js';
|
|
6
|
-
import type { Middleware, Handler, NextFunction, UseMethodParams } from '@tinyhttp/router';
|
|
7
|
-
import { Router } from '@tinyhttp/router';
|
|
8
|
-
import { AppConstructor, AppRenderOptions, AppSettings, TemplateEngine } from './types.js';
|
|
2
|
+
import { Handler, Middleware, NextFunction, UseMethodParams, Router } from '@tinyhttp/router';
|
|
9
3
|
import { TemplateEngineOptions } from './index.js';
|
|
4
|
+
import { ErrorHandler } from './onError.js';
|
|
5
|
+
import { Request } from './request.js';
|
|
6
|
+
import { Response } from './response.js';
|
|
7
|
+
import { AppConstructor, AppRenderOptions, AppSettings, TemplateEngine } from './types.js';
|
|
8
|
+
|
|
10
9
|
/**
|
|
11
10
|
* `App` class - the starting point of tinyhttp app.
|
|
12
11
|
*
|
|
@@ -86,7 +85,7 @@ export declare class App<Req extends Request = Request, Res extends Response = R
|
|
|
86
85
|
* @param options Template engine options
|
|
87
86
|
* @param cb Callback that consumes error and html
|
|
88
87
|
*/
|
|
89
|
-
render<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions>(name: string, data
|
|
88
|
+
render<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions>(name: string, data?: Record<string, unknown>, options?: AppRenderOptions<RenderOptions>, cb?: (err: unknown, html?: unknown) => void): void;
|
|
90
89
|
use(...args: UseMethodParams<Req, Res, App>): this;
|
|
91
90
|
route(path: string): App;
|
|
92
91
|
/**
|
package/dist/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,WAAW,CAAA;AAErD,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAC1F,OAAO,EAAE,MAAM,EAAkB,MAAM,kBAAkB,CAAA;AAGzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAGhD,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,cAAc,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAuB/F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,GAAG,CAAC,GAAG,SAAS,OAAO,GAAG,OAAO,EAAE,GAAG,SAAS,QAAQ,GAAG,QAAQ,CAAE,SAAQ,MAAM,CAAC,GAAG,EAAE,GAAG,EAA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,MAAM,CAAC,aAAa,SAAS,qBAAqB,GAAG,qBAAqB,EACxE,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAClC,OAAO,GAAE,gBAAgB,CAAC,aAAa,CAAyC,EAChF,EAAE,GAAE,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAe,GACpD,IAAI;IA8CP,GAAG,CAAC,GAAG,IAAI,EAAE,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI;IAkElD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG;IAsBxB;;;;OAIG;IACH,OAAO,CAAC,aAAa,SAAS,qBAAqB,GAAG,qBAAqB,EACzE,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,IAAI,CAAC,EAAE,YAAY,GAClB,IAAI;IAyFP;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;CAG9D"}
|
package/dist/extend.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { NextFunction } from '@tinyhttp/router';
|
|
3
|
-
import type { Response } from './response.js';
|
|
1
|
+
import { NextFunction } from '@tinyhttp/router';
|
|
4
2
|
import { App } from './app.js';
|
|
3
|
+
import { Request } from './request.js';
|
|
4
|
+
import { Response } from './response.js';
|
|
5
5
|
import { TemplateEngineOptions } from './types.js';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Extends Request and Response objects with custom properties and methods
|
|
8
9
|
*/
|
package/dist/extend.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../src/extend.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../src/extend.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,cAAc,CAAA;AAE1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEvD;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAC1B,aAAa,SAAS,qBAAqB,+BAA+B,GAAG,WACxE,OAAO,OAAO,QAAQ,CAAC,aAAa,CAAC,QAAQ,YAAY,KAAG,IA4DjE,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Middleware, NextFunction, AsyncHandler as RAsyncHandler, Handler as RHandler, SyncHandler as RSyncHandler } from '@tinyhttp/router';
|
|
2
|
+
import { Request } from './request.js';
|
|
3
|
+
import { Response } from './response.js';
|
|
1
4
|
export { App } from './app.js';
|
|
2
5
|
export * from './request.js';
|
|
3
6
|
export * from './response.js';
|
|
@@ -5,9 +8,6 @@ export { extendMiddleware } from './extend.js';
|
|
|
5
8
|
export { onErrorHandler, type ErrorHandler } from './onError.js';
|
|
6
9
|
export { View } from './view.js';
|
|
7
10
|
export type { AppSettings, TemplateEngineOptions, TemplateEngine, AppConstructor } from './types.js';
|
|
8
|
-
import type { Request } from './request.js';
|
|
9
|
-
import type { Response } from './response.js';
|
|
10
|
-
import type { NextFunction, Handler as RHandler, AsyncHandler as RAsyncHandler, SyncHandler as RSyncHandler, Middleware } from '@tinyhttp/router';
|
|
11
11
|
export type Handler = RHandler<Request, Response>;
|
|
12
12
|
export type AsyncHandler = RAsyncHandler<Request, Response>;
|
|
13
13
|
export type SyncHandler = RSyncHandler<Request, Response>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,YAAY,EAAE,WAAW,EAAE,qBAAqB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEpG,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,YAAY,EAAE,WAAW,EAAE,qBAAqB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEpG,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,YAAY,IAAI,aAAa,EAC7B,OAAO,IAAI,QAAQ,EACnB,WAAW,IAAI,YAAY,EAC5B,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;AACjD,MAAM,MAAM,YAAY,GAAG,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;AAC3D,MAAM,MAAM,WAAW,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;AACzD,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,62 +1,43 @@
|
|
|
1
1
|
import { STATUS_CODES, createServer } from "node:http";
|
|
2
|
-
import { proxyaddr, all, compile } from "@tinyhttp/proxy-addr";
|
|
3
|
-
import { isIP } from "node:net";
|
|
4
2
|
import { getRequestHeader, getQueryParams, getRangeFromHeader, getAccepts, getAcceptsCharsets, getAcceptsEncodings, getAcceptsLanguages, checkIfXMLHttpRequest, getFreshOrStale, getPathname, getURLParams } from "@tinyhttp/req";
|
|
5
3
|
import { getURLParams as getURLParams2 } from "@tinyhttp/req";
|
|
6
4
|
import { Router, pushMiddleware } from "@tinyhttp/router";
|
|
7
|
-
import { getResponseHeader, setHeader, send, json, status, sendStatus, sendFile, setContentType, setLocationHeader, setLinksHeader, setVaryHeader, setCookie, clearCookie, formatResponse, redirect, attachment, download, append } from "@tinyhttp/res";
|
|
8
5
|
import { parse } from "regexparam";
|
|
9
|
-
import {
|
|
6
|
+
import { proxyaddr, all, compile } from "@tinyhttp/proxy-addr";
|
|
7
|
+
import { getResponseHeader, setHeader, send, json, status, sendStatus, sendFile, setContentType, setLocationHeader, setLinksHeader, setVaryHeader, setCookie, clearCookie, formatResponse, redirect, attachment, download, append } from "@tinyhttp/res";
|
|
8
|
+
import { isIP } from "node:net";
|
|
10
9
|
import { statSync } from "node:fs";
|
|
11
|
-
|
|
10
|
+
import { extname, resolve, dirname, basename, join } from "node:path";
|
|
11
|
+
const trustRemoteAddress = ({ socket }, trust) => {
|
|
12
12
|
const val = socket.remoteAddress;
|
|
13
|
-
if (typeof
|
|
14
|
-
|
|
15
|
-
return compile(val || []);
|
|
13
|
+
if (typeof trust !== "function") trust = compile(trust);
|
|
14
|
+
return trust(val, 0);
|
|
16
15
|
};
|
|
17
|
-
const getProtocol = (req) => {
|
|
16
|
+
const getProtocol = (req, trust) => {
|
|
18
17
|
const proto = `http${req.secure ? "s" : ""}`;
|
|
19
|
-
if (!trustRemoteAddress(req))
|
|
20
|
-
return proto;
|
|
18
|
+
if (!trustRemoteAddress(req, trust)) return proto;
|
|
21
19
|
const header = req.headers["X-Forwarded-Proto"] || proto;
|
|
22
20
|
const index = header.indexOf(",");
|
|
23
21
|
return index !== -1 ? header.substring(0, index).trim() : header.trim();
|
|
24
22
|
};
|
|
25
|
-
const getHostname = (req) => {
|
|
23
|
+
const getHostname = (req, trust) => {
|
|
26
24
|
let host = req.get("X-Forwarded-Host");
|
|
27
|
-
if (!host || !trustRemoteAddress(req))
|
|
28
|
-
|
|
29
|
-
if (!host)
|
|
30
|
-
return;
|
|
25
|
+
if (!host || !trustRemoteAddress(req, trust)) host = req.get("Host");
|
|
26
|
+
if (!host) return;
|
|
31
27
|
const index = host.indexOf(":", host[0] === "[" ? host.indexOf("]") + 1 : 0);
|
|
32
28
|
return index !== -1 ? host.substring(0, index) : host;
|
|
33
29
|
};
|
|
34
|
-
const getIP = (req) => proxyaddr(req,
|
|
35
|
-
const getIPs = (req) => all(req,
|
|
36
|
-
const getSubdomains = (req, subdomainOffset = 2) => {
|
|
37
|
-
const hostname = getHostname(req);
|
|
38
|
-
if (!hostname)
|
|
39
|
-
return [];
|
|
30
|
+
const getIP = (req, trust) => proxyaddr(req, trust).replace(/^.*:/, "");
|
|
31
|
+
const getIPs = (req, trust) => all(req, trust);
|
|
32
|
+
const getSubdomains = (req, trust, subdomainOffset = 2) => {
|
|
33
|
+
const hostname = getHostname(req, trust);
|
|
34
|
+
if (!hostname) return [];
|
|
40
35
|
const subdomains = isIP(hostname) ? [hostname] : hostname.split(".").reverse();
|
|
41
36
|
return subdomains.slice(subdomainOffset);
|
|
42
37
|
};
|
|
43
|
-
const onErrorHandler = function(err, _req, res) {
|
|
44
|
-
if (this.onError === onErrorHandler && this.parent)
|
|
45
|
-
return this.parent.onError(err, _req, res);
|
|
46
|
-
if (err instanceof Error)
|
|
47
|
-
console.error(err);
|
|
48
|
-
const code = err.code in STATUS_CODES ? err.code : err.status;
|
|
49
|
-
if (typeof err === "string" || Buffer.isBuffer(err))
|
|
50
|
-
res.writeHead(500).end(err);
|
|
51
|
-
else if (code in STATUS_CODES)
|
|
52
|
-
res.writeHead(code).end(STATUS_CODES[code]);
|
|
53
|
-
else
|
|
54
|
-
res.writeHead(500).end(err.message);
|
|
55
|
-
};
|
|
56
38
|
const renderTemplate = (_req, res, app) => (file, data, options) => {
|
|
57
39
|
app.render(file, data ? { ...res.locals, ...data } : res.locals, options, (err, html) => {
|
|
58
|
-
if (err)
|
|
59
|
-
throw err;
|
|
40
|
+
if (err) throw err;
|
|
60
41
|
res.send(html);
|
|
61
42
|
});
|
|
62
43
|
return res;
|
|
@@ -69,13 +50,18 @@ const extendMiddleware = (app) => (req, res, next) => {
|
|
|
69
50
|
req.app = app;
|
|
70
51
|
res.app = app;
|
|
71
52
|
}
|
|
53
|
+
let trust = settings == null ? void 0 : settings["trust proxy"];
|
|
54
|
+
if (typeof trust !== "function") {
|
|
55
|
+
trust = compile(trust);
|
|
56
|
+
settings["trust proxy"] = trust;
|
|
57
|
+
}
|
|
72
58
|
if (settings == null ? void 0 : settings.networkExtensions) {
|
|
73
|
-
req.protocol = getProtocol(req);
|
|
59
|
+
req.protocol = getProtocol(req, trust);
|
|
74
60
|
req.secure = req.protocol === "https";
|
|
75
|
-
req.hostname = getHostname(req);
|
|
76
|
-
req.subdomains = getSubdomains(req, settings.subdomainOffset);
|
|
77
|
-
req.ip = getIP(req);
|
|
78
|
-
req.ips = getIPs(req);
|
|
61
|
+
req.hostname = getHostname(req, trust);
|
|
62
|
+
req.subdomains = getSubdomains(req, trust, settings.subdomainOffset);
|
|
63
|
+
req.ip = getIP(req, trust);
|
|
64
|
+
req.ips = getIPs(req, trust);
|
|
79
65
|
}
|
|
80
66
|
req.query = getQueryParams(req.url);
|
|
81
67
|
req.range = getRangeFromHeader(req);
|
|
@@ -107,6 +93,14 @@ const extendMiddleware = (app) => (req, res, next) => {
|
|
|
107
93
|
req.stale = !req.fresh;
|
|
108
94
|
next();
|
|
109
95
|
};
|
|
96
|
+
const onErrorHandler = function(err, _req, res) {
|
|
97
|
+
if (this.onError === onErrorHandler && this.parent) return this.parent.onError(err, _req, res);
|
|
98
|
+
if (err instanceof Error) console.error(err);
|
|
99
|
+
const code = err.code in STATUS_CODES ? err.code : err.status;
|
|
100
|
+
if (typeof err === "string" || Buffer.isBuffer(err)) res.writeHead(500).end(err);
|
|
101
|
+
else if (code in STATUS_CODES) res.writeHead(code).end(STATUS_CODES[code]);
|
|
102
|
+
else res.writeHead(500).end(err.message);
|
|
103
|
+
};
|
|
110
104
|
function tryStat(path) {
|
|
111
105
|
try {
|
|
112
106
|
return statSync(path);
|
|
@@ -124,11 +118,10 @@ class View {
|
|
|
124
118
|
throw new Error("No default engine was specified and no extension was provided.");
|
|
125
119
|
let fileName = name;
|
|
126
120
|
if (!this.ext) {
|
|
127
|
-
this.ext = this.defaultEngine[0] !== "." ?
|
|
121
|
+
this.ext = this.defaultEngine[0] !== "." ? `.${this.defaultEngine}` : this.defaultEngine;
|
|
128
122
|
fileName += this.ext;
|
|
129
123
|
}
|
|
130
|
-
if (!opts.engines[this.ext])
|
|
131
|
-
throw new Error(`No engine was found for ${this.ext}`);
|
|
124
|
+
if (!opts.engines[this.ext]) throw new Error(`No engine was found for ${this.ext}`);
|
|
132
125
|
this.engine = opts.engines[this.ext];
|
|
133
126
|
this.path = this.#lookup(fileName);
|
|
134
127
|
}
|
|
@@ -148,12 +141,12 @@ class View {
|
|
|
148
141
|
const ext = this.ext;
|
|
149
142
|
let path = join(dir, file);
|
|
150
143
|
let stat = tryStat(path);
|
|
151
|
-
if (stat
|
|
144
|
+
if (stat == null ? void 0 : stat.isFile()) {
|
|
152
145
|
return path;
|
|
153
146
|
}
|
|
154
|
-
path = join(dir, basename(file, ext),
|
|
147
|
+
path = join(dir, basename(file, ext), `index${ext}`);
|
|
155
148
|
stat = tryStat(path);
|
|
156
|
-
if (stat
|
|
149
|
+
if (stat == null ? void 0 : stat.isFile()) {
|
|
157
150
|
return path;
|
|
158
151
|
}
|
|
159
152
|
}
|
|
@@ -161,14 +154,13 @@ class View {
|
|
|
161
154
|
this.engine(this.path, data, options, cb);
|
|
162
155
|
}
|
|
163
156
|
}
|
|
164
|
-
const lead = (x) => x.charCodeAt(0) === 47 ? x :
|
|
157
|
+
const lead = (x) => x.charCodeAt(0) === 47 ? x : `/${x}`;
|
|
165
158
|
const mount = (fn) => fn instanceof App ? fn.attach : fn;
|
|
166
159
|
const applyHandler = (h) => async (req, res, next) => {
|
|
167
160
|
try {
|
|
168
161
|
if (h[Symbol.toStringTag] === "AsyncFunction") {
|
|
169
162
|
await h(req, res, next);
|
|
170
|
-
} else
|
|
171
|
-
h(req, res, next);
|
|
163
|
+
} else h(req, res, next);
|
|
172
164
|
} catch (e) {
|
|
173
165
|
next(e);
|
|
174
166
|
}
|
|
@@ -186,6 +178,7 @@ class App extends Router {
|
|
|
186
178
|
xPoweredBy: true,
|
|
187
179
|
views: `${process.cwd()}/views`,
|
|
188
180
|
"view cache": process.env.NODE_ENV === "production",
|
|
181
|
+
"trust proxy": 0,
|
|
189
182
|
...options.settings
|
|
190
183
|
};
|
|
191
184
|
this.applyExtensions = options == null ? void 0 : options.applyExtensions;
|
|
@@ -253,28 +246,27 @@ class App extends Router {
|
|
|
253
246
|
* @param options Template engine options
|
|
254
247
|
* @param cb Callback that consumes error and html
|
|
255
248
|
*/
|
|
256
|
-
render(name, data = {}, options = {}, cb) {
|
|
249
|
+
render(name, data = {}, options = {}, cb = () => {
|
|
250
|
+
}) {
|
|
257
251
|
let view;
|
|
258
252
|
const { _locals, ...opts } = options;
|
|
259
253
|
let locals = this.locals;
|
|
260
|
-
if (_locals)
|
|
261
|
-
locals = { ...locals, ..._locals };
|
|
254
|
+
if (_locals) locals = { ...locals, ..._locals };
|
|
262
255
|
locals = { ...locals, ...data };
|
|
263
|
-
if (opts.cache == null)
|
|
264
|
-
opts.cache = this.enabled("view cache");
|
|
256
|
+
if (opts.cache == null) opts.cache = this.enabled("view cache");
|
|
265
257
|
if (opts.cache) {
|
|
266
258
|
view = this.cache[name];
|
|
267
259
|
}
|
|
268
260
|
if (!view) {
|
|
269
|
-
const View2 = this.settings
|
|
261
|
+
const View2 = this.settings.view;
|
|
270
262
|
view = new View2(name, {
|
|
271
263
|
defaultEngine: this.settings["view engine"],
|
|
272
264
|
root: this.settings.views,
|
|
273
265
|
engines: this.engines
|
|
274
266
|
});
|
|
275
267
|
if (!view.path) {
|
|
276
|
-
const dirs = Array.isArray(view.root) && view.root.length > 1 ?
|
|
277
|
-
const err = new Error(
|
|
268
|
+
const dirs = Array.isArray(view.root) && view.root.length > 1 ? `directories "${view.root.slice(0, -1).join('", "')}" or "${view.root[view.root.length - 1]}"` : `directory "${view.root}"`;
|
|
269
|
+
const err = new Error(`Failed to lookup view "${name}" in views ${dirs}`);
|
|
278
270
|
return cb(err);
|
|
279
271
|
}
|
|
280
272
|
if (opts.cache) {
|
|
@@ -288,6 +280,7 @@ class App extends Router {
|
|
|
288
280
|
}
|
|
289
281
|
}
|
|
290
282
|
use(...args) {
|
|
283
|
+
var _a;
|
|
291
284
|
const base = args[0];
|
|
292
285
|
const fns = args.slice(1).flat();
|
|
293
286
|
let pathArray = [];
|
|
@@ -295,10 +288,8 @@ class App extends Router {
|
|
|
295
288
|
fns.unshift(base);
|
|
296
289
|
} else {
|
|
297
290
|
let basePaths = [];
|
|
298
|
-
if (Array.isArray(base))
|
|
299
|
-
|
|
300
|
-
else if (typeof base === "string")
|
|
301
|
-
basePaths = [base];
|
|
291
|
+
if (Array.isArray(base)) basePaths = [...base];
|
|
292
|
+
else if (typeof base === "string") basePaths = [base];
|
|
302
293
|
basePaths = basePaths.filter((element) => {
|
|
303
294
|
if (typeof element === "string") {
|
|
304
295
|
pathArray.push(element);
|
|
@@ -313,16 +304,15 @@ class App extends Router {
|
|
|
313
304
|
let regex;
|
|
314
305
|
for (const fn of fns) {
|
|
315
306
|
if (fn instanceof App) {
|
|
316
|
-
|
|
307
|
+
for (const path of pathArray) {
|
|
317
308
|
regex = parse(path, true);
|
|
318
309
|
fn.mountpath = mountpath;
|
|
319
310
|
this.apps[path] = fn;
|
|
320
311
|
fn.parent = this;
|
|
321
|
-
}
|
|
312
|
+
}
|
|
322
313
|
}
|
|
323
314
|
}
|
|
324
|
-
|
|
325
|
-
var _a;
|
|
315
|
+
for (const path of pathArray) {
|
|
326
316
|
const handlerPaths = [];
|
|
327
317
|
const handlerFunctions = [];
|
|
328
318
|
const handlerPathBase = path === "/" ? "" : lead(path);
|
|
@@ -345,7 +335,7 @@ class App extends Router {
|
|
|
345
335
|
handlers: handlerFunctions.slice(1).map(mount),
|
|
346
336
|
fullPaths: handlerPaths
|
|
347
337
|
});
|
|
348
|
-
}
|
|
338
|
+
}
|
|
349
339
|
return this;
|
|
350
340
|
}
|
|
351
341
|
route(path) {
|
|
@@ -368,8 +358,7 @@ class App extends Router {
|
|
|
368
358
|
*/
|
|
369
359
|
handler(req, res, next) {
|
|
370
360
|
const { xPoweredBy } = this.settings;
|
|
371
|
-
if (xPoweredBy)
|
|
372
|
-
res.setHeader("X-Powered-By", typeof xPoweredBy === "string" ? xPoweredBy : "tinyhttp");
|
|
361
|
+
if (xPoweredBy) res.setHeader("X-Powered-By", typeof xPoweredBy === "string" ? xPoweredBy : "tinyhttp");
|
|
373
362
|
const exts = this.applyExtensions || extendMiddleware(this);
|
|
374
363
|
req.originalUrl = req.url || req.originalUrl;
|
|
375
364
|
const pathname = getPathname(req.originalUrl);
|
|
@@ -408,10 +397,8 @@ class App extends Router {
|
|
|
408
397
|
params = regex ? getURLParams(regex, pathname) : {};
|
|
409
398
|
} catch (e) {
|
|
410
399
|
console.error(e);
|
|
411
|
-
if (e instanceof URIError)
|
|
412
|
-
|
|
413
|
-
else
|
|
414
|
-
throw e;
|
|
400
|
+
if (e instanceof URIError) return res2.sendStatus(400);
|
|
401
|
+
throw e;
|
|
415
402
|
}
|
|
416
403
|
let prefix = path;
|
|
417
404
|
if (regex) {
|
|
@@ -427,10 +414,8 @@ class App extends Router {
|
|
|
427
414
|
if (mw2.type === "mw") {
|
|
428
415
|
req2.url = lead(req2.originalUrl.substring(prefix.length));
|
|
429
416
|
}
|
|
430
|
-
if (!req2.path)
|
|
431
|
-
|
|
432
|
-
if ((_a = this.settings) == null ? void 0 : _a.enableReqRoute)
|
|
433
|
-
req2.route = mw2;
|
|
417
|
+
if (!req2.path) req2.path = getPathname(req2.url);
|
|
418
|
+
if ((_a = this.settings) == null ? void 0 : _a.enableReqRoute) req2.route = mw2;
|
|
434
419
|
await applyHandler(handler)(req2, res2, next2);
|
|
435
420
|
};
|
|
436
421
|
let idx = 0;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/request.ts","../src/onError.ts","../src/response.ts","../src/extend.ts","../src/view.ts","../src/app.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http'\nimport type { ParsedUrlQuery } from 'node:querystring'\n\nimport { Options, Ranges } from 'header-range-parser'\nimport { proxyaddr as proxyAddr, all, compile } from '@tinyhttp/proxy-addr'\n\nimport { App } from './app.js'\nimport type { Middleware } from '@tinyhttp/router'\n\nimport type { URLParams } from '@tinyhttp/req'\nimport { isIP } from 'node:net'\nimport type { Socket } from 'node:net'\nimport type { TLSSocket } from 'node:tls'\n\nexport { getURLParams } from '@tinyhttp/req'\n\nconst trustRemoteAddress = ({ socket }: Pick<Request, 'headers' | 'socket'>) => {\n const val = socket.remoteAddress\n if (typeof val === 'string') return compile(val.split(',').map((x) => x.trim()))\n return compile(val || [])\n}\n\nexport const getProtocol = (req: Request): Protocol => {\n const proto = `http${req.secure ? 's' : ''}`\n\n if (!trustRemoteAddress(req)) return proto\n\n const header = (req.headers['X-Forwarded-Proto'] as string) || proto\n\n const index = header.indexOf(',')\n\n return index !== -1 ? header.substring(0, index).trim() : header.trim()\n}\n\nexport const getHostname = (req: Request): string | undefined => {\n let host: string = req.get('X-Forwarded-Host') as string\n\n if (!host || !trustRemoteAddress(req)) host = req.get('Host') as string\n\n if (!host) return\n\n // IPv6 literal support\n const index = host.indexOf(':', host[0] === '[' ? host.indexOf(']') + 1 : 0)\n\n return index !== -1 ? host.substring(0, index) : host\n}\n\nexport const getIP = (req: Pick<Request, 'headers' | 'connection' | 'socket'>): string | undefined =>\n proxyAddr(req, trustRemoteAddress(req)).replace(/^.*:/, '') // striping the redundant prefix addeded by OS to IPv4 address\n\nexport const getIPs = (req: Pick<Request, 'headers' | 'connection' | 'socket'>): string[] | undefined =>\n all(req, trustRemoteAddress(req))\n\nexport const getSubdomains = (req: Request, subdomainOffset = 2): string[] => {\n const hostname = getHostname(req)\n\n if (!hostname) return []\n\n const subdomains = isIP(hostname) ? [hostname] : hostname.split('.').reverse()\n\n return subdomains.slice(subdomainOffset)\n}\n\nexport type Connection = IncomingMessage['socket'] & {\n encrypted: boolean\n}\n\nexport type Protocol = 'http' | 'https' | string\n\nexport type { URLParams }\n\ntype AcceptsReturns = string | boolean | string[]\n\nexport interface Request extends IncomingMessage {\n originalUrl: string\n path: string\n url: string\n query: ParsedUrlQuery\n params: URLParams\n connection: Connection\n socket: TLSSocket | Socket\n route?: Middleware\n protocol: Protocol\n secure: boolean\n xhr: boolean\n hostname?: string\n ip?: string\n ips?: string[]\n subdomains?: string[]\n get: (header: string) => string | string[] | undefined\n range: (size: number, options?: Options) => -1 | -2 | -3 | Ranges | undefined\n accepts: (...types: string[]) => AcceptsReturns\n acceptsEncodings: (...encodings: string[]) => AcceptsReturns\n acceptsCharsets: (...charsets: string[]) => AcceptsReturns\n acceptsLanguages: (...languages: string[]) => AcceptsReturns\n is: (...types: string[]) => boolean\n cookies?: any\n signedCookies?: any\n secret?: string | string[]\n fresh?: boolean\n stale?: boolean\n body?: any\n app?: App\n}\n","import type { NextFunction } from '@tinyhttp/router'\nimport { STATUS_CODES } from 'node:http'\nimport type { Request } from './request.js'\nimport type { Response } from './response.js'\nimport type { App } from './app.js'\n\nexport type ErrorHandler = (this: App, err: any, req: Request, res: Response, next?: NextFunction) => void\n\nexport const onErrorHandler: ErrorHandler = function (this: App, err: any, _req: Request, res: Response) {\n if (this.onError === onErrorHandler && this.parent) return this.parent.onError(err, _req, res)\n\n if (err instanceof Error) console.error(err)\n\n const code = err.code in STATUS_CODES ? err.code : err.status\n\n if (typeof err === 'string' || Buffer.isBuffer(err)) res.writeHead(500).end(err)\n else if (code in STATUS_CODES) res.writeHead(code).end(STATUS_CODES[code])\n else res.writeHead(500).end(err.message)\n}\n","import { ServerResponse } from 'node:http'\nimport type { SerializeOptions } from '@tinyhttp/cookie'\nimport { Request } from './request.js'\nimport { App } from './app.js'\nimport type { ReadStreamOptions, FormatProps, DownloadOptions } from '@tinyhttp/res'\nimport type { AppRenderOptions, TemplateEngineOptions } from './types.js'\n\nexport const renderTemplate =\n <O extends TemplateEngineOptions = TemplateEngineOptions>(_req: Request, res: Response, app: App) =>\n (file: string, data?: Record<string, unknown>, options?: AppRenderOptions<O>): Response => {\n app.render(file, data ? { ...res.locals, ...data } : res.locals, options, (err: unknown, html: unknown) => {\n if (err) throw err\n res.send(html)\n })\n return res\n }\n\nexport interface Response<B = unknown> extends ServerResponse {\n header(field: string | Record<string, unknown>, val?: string | any[]): Response<B>\n set(field: string | Record<string, unknown>, val?: string | any[]): Response<B>\n get(field: string): string | number | string[]\n send(body: B): Response<B>\n sendFile(path: string, options?: ReadStreamOptions, cb?: (err?: unknown) => void): Response<B>\n json(body: B): Response<B>\n status(status: number): Response<B>\n sendStatus(statusCode: number): Response<B>\n cookie(\n name: string,\n value: string | Record<string, unknown>,\n options?: SerializeOptions & Partial<{ signed: boolean }>\n ): Response<B>\n clearCookie(name: string, options?: SerializeOptions): Response<B>\n location(url: string): Response<B>\n links(links: { [key: string]: string }): Response<B>\n render<O extends TemplateEngineOptions = TemplateEngineOptions>(\n file: string,\n data?: Record<string, any>,\n options?: AppRenderOptions<O>\n ): Response<B>\n vary(field: string): Response<B>\n format(obj: FormatProps): Response<B>\n redirect(url: string, status?: number): Response<B>\n type(type: string): Response<B>\n download(path: string, filename: string, options?: DownloadOptions, cb?: (err?: unknown) => void): Response<B>\n attachment(filename?: string): Response<B>\n app?: App\n locals: Record<string, any>\n /**\n * Send JSON response with JSONP callback support.\n *\n * To enable this method, install the `@tinyhttp/jsonp` package and attach the method to `res.jsonp` property.\n *\n * @param obj Response object\n */\n jsonp(obj: any): Response<B>\n\n append(field: string, value: any): Response<B>\n}\n","import { getSubdomains, Request } from './request.js'\nimport type { NextFunction } from '@tinyhttp/router'\nimport type { Response } from './response.js'\nimport {\n getFreshOrStale,\n getRangeFromHeader,\n getRequestHeader,\n checkIfXMLHttpRequest,\n getQueryParams,\n getAccepts,\n getAcceptsCharsets,\n getAcceptsEncodings,\n getAcceptsLanguages\n} from '@tinyhttp/req'\nimport { getProtocol, getHostname, getIP, getIPs } from './request.js'\nimport {\n send,\n json,\n status,\n setCookie,\n clearCookie,\n setHeader,\n getResponseHeader,\n setLocationHeader,\n setLinksHeader,\n sendStatus,\n setVaryHeader,\n sendFile,\n formatResponse,\n redirect,\n setContentType,\n attachment,\n download,\n append\n} from '@tinyhttp/res'\nimport { renderTemplate } from './response.js'\nimport { App } from './app.js'\nimport { TemplateEngineOptions } from './types.js'\n\n/**\n * Extends Request and Response objects with custom properties and methods\n */\nexport const extendMiddleware =\n <EngineOptions extends TemplateEngineOptions = TemplateEngineOptions>(app: App) =>\n (req: Request, res: Response<EngineOptions>, next: NextFunction): void => {\n const { settings } = app\n\n res.get = getResponseHeader(res)\n req.get = getRequestHeader(req)\n\n if (settings?.bindAppToReqRes) {\n req.app = app\n res.app = app\n }\n\n if (settings?.networkExtensions) {\n req.protocol = getProtocol(req)\n req.secure = req.protocol === 'https'\n req.hostname = getHostname(req)\n req.subdomains = getSubdomains(req, settings.subdomainOffset)\n req.ip = getIP(req)\n req.ips = getIPs(req)\n }\n\n req.query = getQueryParams(req.url)\n\n req.range = getRangeFromHeader(req)\n req.accepts = getAccepts(req)\n req.acceptsCharsets = getAcceptsCharsets(req)\n req.acceptsEncodings = getAcceptsEncodings(req)\n req.acceptsLanguages = getAcceptsLanguages(req)\n\n req.xhr = checkIfXMLHttpRequest(req)\n\n res.header = res.set = setHeader<Response>(res)\n res.send = send<Request, Response>(req, res)\n res.json = json<Response>(res)\n res.status = status<Response>(res)\n res.sendStatus = sendStatus<Request, Response>(req, res)\n res.sendFile = sendFile<Request, Response>(req, res)\n res.type = setContentType<Response>(res)\n res.location = setLocationHeader<Request, Response>(req, res)\n res.links = setLinksHeader<Response>(res)\n res.vary = setVaryHeader<Response>(res)\n res.cookie = setCookie<Request, Response>(req, res)\n res.clearCookie = clearCookie<Request, Response>(req, res)\n res.render = renderTemplate(req, res, app)\n res.format = formatResponse(req, res, next)\n res.redirect = redirect(req, res, next)\n res.attachment = attachment<Response>(res)\n res.download = download<Request, Response>(req, res)\n res.append = append<Response>(res)\n res.locals = res.locals || Object.create(null)\n\n Object.defineProperty(req, 'fresh', { get: getFreshOrStale.bind(null, req, res), configurable: true })\n req.stale = !req.fresh\n\n next()\n }\n","/*!\n * Ported from https://github.com/expressjs/express/blob/master/lib/view.js\n * express\n * Copyright(c) 2009-2013 TJ Holowaychuk\n * Copyright(c) 2013 Roman Shtylman\n * Copyright(c) 2014-2015 Douglas Christopher Wilson\n * MIT Licensed\n */\n\nimport { extname, resolve, dirname, basename, join } from 'node:path'\nimport { TemplateEngineOptions, TemplateEngine } from './types.js'\nimport { statSync } from 'node:fs'\n\nfunction tryStat(path: string) {\n try {\n return statSync(path)\n } catch (e) {\n return undefined\n }\n}\n\n/**\n * Initialize a new `View` with the given `name`.\n *\n * Options:\n *\n * - `defaultEngine` the default template engine name\n * - `engines` template engine require() cache\n * - `root` root path for view lookup\n *\n * @param name\n * @param options\n * @public\n */\n\nexport class View<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions> {\n ext: string\n defaultEngine: string\n name: string\n engine: TemplateEngine<RenderOptions>\n path: string\n root: string | string[]\n constructor(\n name: string,\n opts: Partial<{\n defaultEngine: string\n root: string | string[]\n engines: Record<string, TemplateEngine<RenderOptions>>\n }> = {}\n ) {\n this.ext = extname(name)\n this.name = name\n this.root = opts.root\n this.defaultEngine = opts.defaultEngine\n\n if (!this.ext && !this.defaultEngine)\n throw new Error('No default engine was specified and no extension was provided.')\n\n let fileName = name\n\n if (!this.ext) {\n // get extension from default engine name\n this.ext = this.defaultEngine[0] !== '.' ? '.' + this.defaultEngine : this.defaultEngine\n\n fileName += this.ext\n }\n\n if (!opts.engines[this.ext]) throw new Error(`No engine was found for ${this.ext}`)\n\n this.engine = opts.engines[this.ext]\n this.path = this.#lookup(fileName)\n }\n #lookup(name: string) {\n let path: string\n const roots = [].concat(this.root)\n\n for (let i = 0; i < roots.length && !path; i++) {\n const root = roots[i]\n // resolve the path\n const loc = resolve(root, name)\n const dir = dirname(loc)\n const file = basename(loc)\n\n // resolve the file\n path = this.#resolve(dir, file)\n }\n\n return path\n }\n #resolve(dir: string, file: string) {\n const ext = this.ext\n\n // <path>.<ext>\n let path = join(dir, file)\n let stat = tryStat(path)\n\n if (stat && stat.isFile()) {\n return path\n }\n\n // <path>/index.<ext>\n path = join(dir, basename(file, ext), 'index' + ext)\n stat = tryStat(path)\n\n if (stat && stat.isFile()) {\n return path\n }\n }\n render(options: RenderOptions, data: Record<string, unknown>, cb: (err: Error | null, html: unknown) => void) {\n this.engine(this.path, data, options, cb)\n }\n}\n","import { createServer, Server } from 'node:http'\nimport { getURLParams } from './request.js'\nimport type { Request, URLParams } from './request.js'\nimport type { Response } from './response.js'\nimport type { ErrorHandler } from './onError.js'\nimport { onErrorHandler } from './onError.js'\nimport type { Middleware, Handler, NextFunction, UseMethodParams } from '@tinyhttp/router'\nimport { Router, pushMiddleware } from '@tinyhttp/router'\nimport { extendMiddleware } from './extend.js'\nimport { parse as rg } from 'regexparam'\nimport { getPathname } from '@tinyhttp/req'\nimport { AppConstructor, AppRenderOptions, AppSettings, TemplateEngine } from './types.js'\nimport { TemplateEngineOptions } from './index.js'\nimport { View } from './view.js'\n\n/**\n * Add leading slash if not present (e.g. path -> /path, /path -> /path)\n * @param x\n */\nconst lead = (x: string) => (x.charCodeAt(0) === 47 ? x : '/' + x)\n\nconst mount = (fn: App | Handler) => (fn instanceof App ? fn.attach : fn)\n\nconst applyHandler =\n <Req, Res>(h: Handler<Req, Res>) =>\n async (req: Req, res: Res, next?: NextFunction) => {\n try {\n if (h[Symbol.toStringTag] === 'AsyncFunction') {\n await h(req, res, next)\n } else h(req, res, next)\n } catch (e) {\n next(e)\n }\n }\n\n/**\n * `App` class - the starting point of tinyhttp app.\n *\n * With the `App` you can:\n * * use routing methods and `.use(...)`\n * * set no match (404) and error (500) handlers\n * * configure template engines\n * * store data in locals\n * * listen the http server on a specified port\n *\n * In case you use TypeScript, you can pass custom types to this class because it is also a generic class.\n *\n * Example:\n *\n * ```ts\n * interface CoolReq extends Request {\n * genericsAreDope: boolean\n * }\n *\n * const app = App<any, CoolReq, Response>()\n * ```\n */\nexport class App<Req extends Request = Request, Res extends Response = Response> extends Router<App, Req, Res> {\n middleware: Middleware<Req, Res>[] = []\n locals: Record<string, unknown> = {}\n noMatchHandler: Handler\n onError: ErrorHandler\n settings: AppSettings\n engines: Record<string, TemplateEngine> = {}\n applyExtensions: (req: Request, res: Response, next: NextFunction) => void\n attach: (req: Req, res: Res) => void\n cache: Record<string, unknown>\n\n constructor(options: AppConstructor<Req, Res> = {}) {\n super()\n this.onError = options?.onError || onErrorHandler\n this.noMatchHandler = options?.noMatchHandler || this.onError.bind(this, { code: 404 })\n this.settings = {\n view: View,\n xPoweredBy: true,\n views: `${process.cwd()}/views`,\n 'view cache': process.env.NODE_ENV === 'production',\n ...options.settings\n }\n this.applyExtensions = options?.applyExtensions\n this.attach = (req, res) => setImmediate(this.handler.bind(this, req, res, undefined), req, res)\n this.cache = {}\n }\n\n /**\n * Set app setting\n * @param setting setting name\n * @param value setting value\n */\n set<K extends keyof AppSettings>(setting: K, value: AppSettings[K]): this {\n this.settings[setting] = value\n\n return this\n }\n\n /**\n * Enable app setting\n * @param setting Setting name\n */\n enable<K extends keyof AppSettings>(setting: K): this {\n this.settings[setting] = true as AppSettings[K]\n\n return this\n }\n\n /**\n * Check if setting is enabled\n * @param setting Setting name\n * @returns\n */\n enabled<K extends keyof AppSettings>(setting: K): boolean {\n return Boolean(this.settings[setting])\n }\n\n /**\n * Disable app setting\n * @param setting Setting name\n */\n disable<K extends keyof AppSettings>(setting: K): this {\n this.settings[setting] = false as AppSettings[K]\n\n return this\n }\n\n /**\n * Return the app's absolute pathname\n * based on the parent(s) that have\n * mounted it.\n *\n * For example if the application was\n * mounted as `\"/admin\"`, which itself\n * was mounted as `\"/blog\"` then the\n * return value would be `\"/blog/admin\"`.\n *\n */\n path(): string {\n return this.parent ? this.parent.path() + this.mountpath : ''\n }\n\n /**\n * Register a template engine with extension\n */\n engine<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions>(\n ext: string,\n fn: TemplateEngine<RenderOptions>\n ): this {\n this.engines[ext[0] === '.' ? ext : `.${ext}`] = fn\n\n return this\n }\n\n /**\n * Render a template\n * @param file What to render\n * @param data data that is passed to a template\n * @param options Template engine options\n * @param cb Callback that consumes error and html\n */\n render<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions>(\n name: string,\n data: Record<string, unknown> = {},\n options: AppRenderOptions<RenderOptions> = {} as AppRenderOptions<RenderOptions>,\n cb: (err: unknown, html?: unknown) => void\n ): void {\n let view: View | undefined\n\n const { _locals, ...opts } = options\n\n let locals = this.locals\n\n if (_locals) locals = { ...locals, ..._locals }\n\n locals = { ...locals, ...data }\n\n if (opts.cache == null) (opts.cache as boolean) = this.enabled('view cache')\n\n if (opts.cache) {\n view = this.cache[name] as View\n }\n\n if (!view) {\n const View = this.settings['view']\n view = new View(name, {\n defaultEngine: this.settings['view engine'],\n root: this.settings.views,\n engines: this.engines\n })\n\n if (!view.path) {\n const dirs =\n Array.isArray(view.root) && view.root.length > 1\n ? 'directories \"' + view.root.slice(0, -1).join('\", \"') + '\" or \"' + view.root[view.root.length - 1] + '\"'\n : 'directory \"' + view.root + '\"'\n const err = new Error('Failed to lookup view \"' + name + '\" in views ' + dirs)\n\n return cb(err)\n }\n\n if (opts.cache) {\n this.cache[name] = view\n }\n }\n\n try {\n view.render(opts, locals, cb)\n } catch (err) {\n cb(err)\n }\n }\n use(...args: UseMethodParams<Req, Res, App>): this {\n const base = args[0]\n\n const fns = args.slice(1).flat()\n\n let pathArray = []\n if (typeof base === 'function' || base instanceof App) {\n fns.unshift(base)\n } else {\n // if base is not an array of paths, then convert it to an array.\n let basePaths = []\n if (Array.isArray(base)) basePaths = [...base]\n else if (typeof base === 'string') basePaths = [base]\n\n basePaths = basePaths.filter((element) => {\n if (typeof element === 'string') {\n pathArray.push(element)\n return false\n }\n return true\n })\n fns.unshift(...basePaths)\n }\n pathArray = pathArray.length ? pathArray.map((path) => lead(path)) : ['/']\n\n const mountpath = pathArray.join(', ')\n let regex: { keys: string[]; pattern: RegExp }\n\n for (const fn of fns) {\n if (fn instanceof App) {\n pathArray.forEach((path) => {\n regex = rg(path, true)\n fn.mountpath = mountpath\n this.apps[path] = fn\n fn.parent = this\n })\n }\n }\n pathArray.forEach((path) => {\n const handlerPaths = []\n const handlerFunctions = []\n const handlerPathBase = path === '/' ? '' : lead(path)\n for (const fn of fns) {\n if (fn instanceof App && fn.middleware?.length) {\n for (const mw of fn.middleware) {\n handlerPaths.push(handlerPathBase + lead(mw.path))\n handlerFunctions.push(fn)\n }\n } else {\n handlerPaths.push('')\n handlerFunctions.push(fn)\n }\n }\n pushMiddleware(this.middleware)({\n path,\n regex,\n type: 'mw',\n handler: mount(handlerFunctions[0] as Handler),\n handlers: handlerFunctions.slice(1).map(mount),\n fullPaths: handlerPaths\n })\n })\n return this\n }\n\n route(path: string): App {\n const app = new App({ settings: this.settings })\n\n this.use(path, app)\n\n return app\n }\n\n #find(url: string): Middleware<Req, Res>[] {\n return this.middleware.filter((m) => {\n m.regex = m.regex || rg(m.path, m.type === 'mw')\n\n let fullPathRegex: { keys: string[]; pattern: RegExp }\n\n m.fullPath && typeof m.fullPath === 'string'\n ? (fullPathRegex = rg(m.fullPath, m.type === 'mw'))\n : (fullPathRegex = null)\n\n return m.regex.pattern.test(url) && (m.type === 'mw' && fullPathRegex ? fullPathRegex.pattern.test(url) : true)\n })\n }\n\n /**\n * Extends Req / Res objects, pushes 404 and 500 handlers, dispatches middleware\n * @param req Req object\n * @param res Res object\n */\n handler<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions>(\n req: Req,\n res: Res,\n next?: NextFunction\n ): void {\n /* Set X-Powered-By header */\n const { xPoweredBy } = this.settings\n if (xPoweredBy) res.setHeader('X-Powered-By', typeof xPoweredBy === 'string' ? xPoweredBy : 'tinyhttp')\n\n const exts = this.applyExtensions || extendMiddleware<RenderOptions>(this)\n\n req.originalUrl = req.url || req.originalUrl\n\n const pathname = getPathname(req.originalUrl)\n\n const matched = this.#find(pathname)\n\n const mw: Middleware[] = [\n {\n handler: exts,\n type: 'mw',\n path: '/'\n },\n ...matched.filter((x) => req.method === 'HEAD' || (x.method ? x.method === req.method : true))\n ]\n\n if (matched[0] != null) {\n mw.push({\n type: 'mw',\n handler: (req, res, next) => {\n if (req.method === 'HEAD') {\n res.statusCode = 204\n return res.end('')\n }\n next()\n },\n path: '/'\n })\n }\n\n mw.push({\n handler: this.noMatchHandler,\n type: 'mw',\n path: '/'\n })\n\n const handle = (mw: Middleware) => async (req: Req, res: Res, next?: NextFunction) => {\n const { path, handler, regex } = mw\n\n let params: URLParams\n\n try {\n params = regex ? getURLParams(regex, pathname) : {}\n } catch (e) {\n console.error(e)\n if (e instanceof URIError) return res.sendStatus(400) // Handle malformed URI\n else throw e\n }\n\n // Warning: users should not use :wild as a pattern\n let prefix = path\n if (regex) {\n for (const key of regex.keys) {\n if (key === 'wild') {\n prefix = prefix.replace('*', params.wild)\n } else {\n prefix = prefix.replace(`:${key}`, params[key])\n }\n }\n }\n\n req.params = { ...req.params, ...params }\n\n if (mw.type === 'mw') {\n req.url = lead(req.originalUrl.substring(prefix.length))\n }\n\n if (!req.path) req.path = getPathname(req.url)\n\n if (this.settings?.enableReqRoute) req.route = mw\n\n await applyHandler<Req, Res>(handler as unknown as Handler<Req, Res>)(req, res, next)\n }\n\n let idx = 0\n\n const loop = () => res.writableEnded || (idx < mw.length && handle(mw[idx++])(req, res, next))\n\n next = next || ((err) => (err ? this.onError(err, req, res) : loop()))\n\n loop()\n }\n\n /**\n * Creates HTTP server and dispatches middleware\n * @param port server listening port\n * @param Server callback after server starts listening\n * @param host server listening host\n */\n listen(port?: number, cb?: () => void, host?: string): Server {\n return createServer().on('request', this.attach).listen(port, host, cb)\n }\n}\n"],"names":["proxyAddr","View","rg","req","res","next","mw"],"mappings":";;;;;;;;;;AAgBA,MAAM,qBAAqB,CAAC,EAAE,aAAkD;AAC9E,QAAM,MAAM,OAAO;AACnB,MAAI,OAAO,QAAQ;AAAiB,WAAA,QAAQ,IAAI,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACxE,SAAA,QAAQ,OAAO,CAAA,CAAE;AAC1B;AAEa,MAAA,cAAc,CAAC,QAA2B;AACrD,QAAM,QAAQ,OAAO,IAAI,SAAS,MAAM,EAAE;AAEtC,MAAA,CAAC,mBAAmB,GAAG;AAAU,WAAA;AAErC,QAAM,SAAU,IAAI,QAAQ,mBAAmB,KAAgB;AAEzD,QAAA,QAAQ,OAAO,QAAQ,GAAG;AAEzB,SAAA,UAAU,KAAK,OAAO,UAAU,GAAG,KAAK,EAAE,KAAA,IAAS,OAAO,KAAK;AACxE;AAEa,MAAA,cAAc,CAA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,MAAKC,MAAKC,KAAI;AAAA,IAAA;AAGtF,QAAI,MAAM;AAEV,UAAM,OAAO,MAAM,IAAI,iBAAkB,MAAM,GAAG,UAAU,OAAO,GAAG,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI;AAErF,WAAA,SAAS,CAAC,QAAS,MAAM,KAAK,QAAQ,KAAK,KAAK,GAAG,IAAI,KAAK;AAE9D;EACP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,MAAe,IAAiB,MAAuB;AACrD,WAAA,aAAe,EAAA,GAAG,WAAW,KAAK,MAAM,EAAE,OAAO,MAAM,MAAM,EAAE;AAAA,EACxE;AACF;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/request.ts","../src/response.ts","../src/extend.ts","../src/onError.ts","../src/view.ts","../src/app.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http'\nimport type { ParsedUrlQuery } from 'node:querystring'\n\nimport { type Trust, all, compile, proxyaddr as proxyAddr } from '@tinyhttp/proxy-addr'\nimport type { Options, Ranges } from 'header-range-parser'\n\nimport type { Middleware } from '@tinyhttp/router'\nimport type { App } from './app.js'\n\nimport { isIP } from 'node:net'\nimport type { Socket } from 'node:net'\nimport type { TLSSocket } from 'node:tls'\nimport type { URLParams } from '@tinyhttp/req'\n\nexport { getURLParams } from '@tinyhttp/req'\n\nconst trustRemoteAddress = ({ socket }: Pick<Request, 'headers' | 'socket'>, trust: Trust): boolean => {\n const val = socket.remoteAddress\n if (typeof trust !== 'function') trust = compile(trust)\n return trust(val, 0)\n}\n\nexport const getProtocol = (req: Request, trust: Trust): Protocol => {\n const proto = `http${req.secure ? 's' : ''}`\n\n if (!trustRemoteAddress(req, trust)) return proto\n\n const header = (req.headers['X-Forwarded-Proto'] as string) || proto\n\n const index = header.indexOf(',')\n\n return index !== -1 ? header.substring(0, index).trim() : header.trim()\n}\n\nexport const getHostname = (req: Request, trust: Trust): string | undefined => {\n let host: string = req.get('X-Forwarded-Host') as string\n\n if (!host || !trustRemoteAddress(req, trust)) host = req.get('Host') as string\n\n if (!host) return\n\n // IPv6 literal support\n const index = host.indexOf(':', host[0] === '[' ? host.indexOf(']') + 1 : 0)\n\n return index !== -1 ? host.substring(0, index) : host\n}\n\nexport const getIP = (req: Pick<Request, 'headers' | 'connection' | 'socket'>, trust: Trust): string | undefined =>\n proxyAddr(req, trust).replace(/^.*:/, '') // striping the redundant prefix addeded by OS to IPv4 address\n\nexport const getIPs = (req: Pick<Request, 'headers' | 'connection' | 'socket'>, trust: Trust): string[] | undefined =>\n all(req, trust)\n\nexport const getSubdomains = (req: Request, trust: Trust, subdomainOffset = 2): string[] => {\n const hostname = getHostname(req, trust)\n\n if (!hostname) return []\n\n const subdomains = isIP(hostname) ? [hostname] : hostname.split('.').reverse()\n\n return subdomains.slice(subdomainOffset)\n}\n\nexport type Connection = IncomingMessage['socket'] & {\n encrypted: boolean\n}\n\nexport type Protocol = 'http' | 'https' | string\n\nexport type { URLParams }\n\ntype AcceptsReturns = string | boolean | string[]\n\nexport interface Request extends IncomingMessage {\n originalUrl: string\n path: string\n url: string\n query: ParsedUrlQuery\n params: URLParams\n connection: Connection\n socket: TLSSocket | Socket\n route?: Middleware\n protocol: Protocol\n secure: boolean\n xhr: boolean\n hostname?: string\n ip?: string\n ips?: string[]\n subdomains?: string[]\n get: (header: string) => string | string[] | undefined\n range: (size: number, options?: Options) => -1 | -2 | -3 | Ranges | undefined\n accepts: (...types: string[]) => AcceptsReturns\n acceptsEncodings: (...encodings: string[]) => AcceptsReturns\n acceptsCharsets: (...charsets: string[]) => AcceptsReturns\n acceptsLanguages: (...languages: string[]) => AcceptsReturns\n is: (...types: string[]) => boolean\n cookies?: any\n signedCookies?: any\n secret?: string | string[]\n fresh?: boolean\n stale?: boolean\n body?: any\n app?: App\n}\n","import type { ServerResponse } from 'node:http'\nimport type { SerializeOptions } from '@tinyhttp/cookie'\nimport type { DownloadOptions, FormatProps, ReadStreamOptions } from '@tinyhttp/res'\nimport type { App } from './app.js'\nimport type { Request } from './request.js'\nimport type { AppRenderOptions, TemplateEngineOptions } from './types.js'\n\nexport const renderTemplate =\n <O extends TemplateEngineOptions = TemplateEngineOptions>(_req: Request, res: Response, app: App) =>\n (file: string, data?: Record<string, unknown>, options?: AppRenderOptions<O>): Response => {\n app.render(file, data ? { ...res.locals, ...data } : res.locals, options, (err: unknown, html: unknown) => {\n if (err) throw err\n res.send(html)\n })\n return res\n }\n\nexport interface Response<B = unknown> extends ServerResponse {\n header(field: string | Record<string, unknown>, val?: string | any[]): Response<B>\n set(field: string | Record<string, unknown>, val?: string | any[]): Response<B>\n get(field: string): string | number | string[]\n send(body: B): Response<B>\n sendFile(path: string, options?: ReadStreamOptions, cb?: (err?: unknown) => void): Response<B>\n json(body: B): Response<B>\n status(status: number): Response<B>\n sendStatus(statusCode: number): Response<B>\n cookie(\n name: string,\n value: string | Record<string, unknown>,\n options?: SerializeOptions & Partial<{ signed: boolean }>\n ): Response<B>\n clearCookie(name: string, options?: SerializeOptions): Response<B>\n location(url: string): Response<B>\n links(links: { [key: string]: string }): Response<B>\n render<O extends TemplateEngineOptions = TemplateEngineOptions>(\n file: string,\n data?: Record<string, any>,\n options?: AppRenderOptions<O>\n ): Response<B>\n vary(field: string): Response<B>\n format(obj: FormatProps): Response<B>\n redirect(url: string, status?: number): Response<B>\n type(type: string): Response<B>\n download(path: string, filename: string, options?: DownloadOptions, cb?: (err?: unknown) => void): Response<B>\n attachment(filename?: string): Response<B>\n app?: App\n locals: Record<string, any>\n /**\n * Send JSON response with JSONP callback support.\n *\n * To enable this method, install the `@tinyhttp/jsonp` package and attach the method to `res.jsonp` property.\n *\n * @param obj Response object\n */\n jsonp(obj: any): Response<B>\n\n append(field: string, value: any): Response<B>\n}\n","import { compile } from '@tinyhttp/proxy-addr'\nimport {\n checkIfXMLHttpRequest,\n getAccepts,\n getAcceptsCharsets,\n getAcceptsEncodings,\n getAcceptsLanguages,\n getFreshOrStale,\n getQueryParams,\n getRangeFromHeader,\n getRequestHeader\n} from '@tinyhttp/req'\nimport {\n append,\n attachment,\n clearCookie,\n download,\n formatResponse,\n getResponseHeader,\n json,\n redirect,\n send,\n sendFile,\n sendStatus,\n setContentType,\n setCookie,\n setHeader,\n setLinksHeader,\n setLocationHeader,\n setVaryHeader,\n status\n} from '@tinyhttp/res'\nimport type { NextFunction } from '@tinyhttp/router'\nimport type { App } from './app.js'\nimport { type Request, getSubdomains } from './request.js'\nimport { getHostname, getIP, getIPs, getProtocol } from './request.js'\nimport type { Response } from './response.js'\nimport { renderTemplate } from './response.js'\nimport type { TemplateEngineOptions } from './types.js'\n\n/**\n * Extends Request and Response objects with custom properties and methods\n */\nexport const extendMiddleware =\n <EngineOptions extends TemplateEngineOptions = TemplateEngineOptions>(app: App) =>\n (req: Request, res: Response<EngineOptions>, next: NextFunction): void => {\n const { settings } = app\n\n res.get = getResponseHeader(res)\n req.get = getRequestHeader(req)\n\n if (settings?.bindAppToReqRes) {\n req.app = app\n res.app = app\n }\n\n let trust = settings?.['trust proxy']\n if (typeof trust !== 'function') {\n trust = compile(trust)\n settings['trust proxy'] = trust\n }\n\n if (settings?.networkExtensions) {\n req.protocol = getProtocol(req, trust)\n req.secure = req.protocol === 'https'\n req.hostname = getHostname(req, trust)\n req.subdomains = getSubdomains(req, trust, settings.subdomainOffset)\n req.ip = getIP(req, trust)\n req.ips = getIPs(req, trust)\n }\n\n req.query = getQueryParams(req.url)\n\n req.range = getRangeFromHeader(req)\n req.accepts = getAccepts(req)\n req.acceptsCharsets = getAcceptsCharsets(req)\n req.acceptsEncodings = getAcceptsEncodings(req)\n req.acceptsLanguages = getAcceptsLanguages(req)\n\n req.xhr = checkIfXMLHttpRequest(req)\n\n res.header = res.set = setHeader<Response>(res)\n res.send = send<Request, Response>(req, res)\n res.json = json<Response>(res)\n res.status = status<Response>(res)\n res.sendStatus = sendStatus<Request, Response>(req, res)\n res.sendFile = sendFile<Request, Response>(req, res)\n res.type = setContentType<Response>(res)\n res.location = setLocationHeader<Request, Response>(req, res)\n res.links = setLinksHeader<Response>(res)\n res.vary = setVaryHeader<Response>(res)\n res.cookie = setCookie<Request, Response>(req, res)\n res.clearCookie = clearCookie<Request, Response>(req, res)\n res.render = renderTemplate(req, res, app)\n res.format = formatResponse(req, res, next)\n res.redirect = redirect(req, res, next)\n res.attachment = attachment<Response>(res)\n res.download = download<Request, Response>(req, res)\n res.append = append<Response>(res)\n res.locals = res.locals || Object.create(null)\n\n Object.defineProperty(req, 'fresh', { get: getFreshOrStale.bind(null, req, res), configurable: true })\n req.stale = !req.fresh\n\n next()\n }\n","import { STATUS_CODES } from 'node:http'\nimport type { NextFunction } from '@tinyhttp/router'\nimport type { App } from './app.js'\nimport type { Request } from './request.js'\nimport type { Response } from './response.js'\n\nexport type ErrorHandler = (this: App, err: any, req: Request, res: Response, next?: NextFunction) => void\n\nexport const onErrorHandler: ErrorHandler = function (this: App, err: any, _req: Request, res: Response) {\n if (this.onError === onErrorHandler && this.parent) return this.parent.onError(err, _req, res)\n\n if (err instanceof Error) console.error(err)\n\n const code = err.code in STATUS_CODES ? err.code : err.status\n\n if (typeof err === 'string' || Buffer.isBuffer(err)) res.writeHead(500).end(err)\n else if (code in STATUS_CODES) res.writeHead(code).end(STATUS_CODES[code])\n else res.writeHead(500).end(err.message)\n}\n","/*!\n * Ported from https://github.com/expressjs/express/blob/master/lib/view.js\n * express\n * Copyright(c) 2009-2013 TJ Holowaychuk\n * Copyright(c) 2013 Roman Shtylman\n * Copyright(c) 2014-2015 Douglas Christopher Wilson\n * MIT Licensed\n */\n\nimport { statSync } from 'node:fs'\nimport { basename, dirname, extname, join, resolve } from 'node:path'\nimport type { TemplateEngine, TemplateEngineOptions } from './types.js'\n\nfunction tryStat(path: string) {\n try {\n return statSync(path)\n } catch (e) {\n return undefined\n }\n}\n\n/**\n * Initialize a new `View` with the given `name`.\n *\n * Options:\n *\n * - `defaultEngine` the default template engine name\n * - `engines` template engine require() cache\n * - `root` root path for view lookup\n *\n * @param name\n * @param options\n * @public\n */\n\nexport class View<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions> {\n ext: string\n defaultEngine: string\n name: string\n engine: TemplateEngine<RenderOptions>\n path: string\n root: string | string[]\n constructor(\n name: string,\n opts: Partial<{\n defaultEngine: string\n root: string | string[]\n engines: Record<string, TemplateEngine<RenderOptions>>\n }> = {}\n ) {\n this.ext = extname(name)\n this.name = name\n this.root = opts.root\n this.defaultEngine = opts.defaultEngine\n\n if (!this.ext && !this.defaultEngine)\n throw new Error('No default engine was specified and no extension was provided.')\n\n let fileName = name\n\n if (!this.ext) {\n // get extension from default engine name\n this.ext = this.defaultEngine[0] !== '.' ? `.${this.defaultEngine}` : this.defaultEngine\n\n fileName += this.ext\n }\n\n if (!opts.engines[this.ext]) throw new Error(`No engine was found for ${this.ext}`)\n\n this.engine = opts.engines[this.ext]\n this.path = this.#lookup(fileName)\n }\n #lookup(name: string) {\n let path: string\n const roots = [].concat(this.root)\n\n for (let i = 0; i < roots.length && !path; i++) {\n const root = roots[i]\n // resolve the path\n const loc = resolve(root, name)\n const dir = dirname(loc)\n const file = basename(loc)\n\n // resolve the file\n path = this.#resolve(dir, file)\n }\n\n return path\n }\n #resolve(dir: string, file: string) {\n const ext = this.ext\n\n // <path>.<ext>\n let path = join(dir, file)\n let stat = tryStat(path)\n\n if (stat?.isFile()) {\n return path\n }\n\n // <path>/index.<ext>\n path = join(dir, basename(file, ext), `index${ext}`)\n stat = tryStat(path)\n\n if (stat?.isFile()) {\n return path\n }\n }\n render(options: RenderOptions, data: Record<string, unknown>, cb: (err: Error | null, html: unknown) => void) {\n this.engine(this.path, data, options, cb)\n }\n}\n","import { type Server, createServer } from 'node:http'\nimport { getPathname } from '@tinyhttp/req'\nimport type { Handler, Middleware, NextFunction, UseMethodParams } from '@tinyhttp/router'\nimport { Router, pushMiddleware } from '@tinyhttp/router'\nimport { parse as rg } from 'regexparam'\nimport { extendMiddleware } from './extend.js'\nimport type { TemplateEngineOptions } from './index.js'\nimport type { ErrorHandler } from './onError.js'\nimport { onErrorHandler } from './onError.js'\nimport { getURLParams } from './request.js'\nimport type { Request, URLParams } from './request.js'\nimport type { Response } from './response.js'\nimport type { AppConstructor, AppRenderOptions, AppSettings, TemplateEngine } from './types.js'\nimport { View } from './view.js'\n\n/**\n * Add leading slash if not present (e.g. path -> /path, /path -> /path)\n * @param x\n */\nconst lead = (x: string) => (x.charCodeAt(0) === 47 ? x : `/${x}`)\n\nconst mount = (fn: App | Handler) => (fn instanceof App ? fn.attach : fn)\n\nconst applyHandler =\n <Req, Res>(h: Handler<Req, Res>) =>\n async (req: Req, res: Res, next?: NextFunction) => {\n try {\n if (h[Symbol.toStringTag] === 'AsyncFunction') {\n await h(req, res, next)\n } else h(req, res, next)\n } catch (e) {\n next(e)\n }\n }\n\n/**\n * `App` class - the starting point of tinyhttp app.\n *\n * With the `App` you can:\n * * use routing methods and `.use(...)`\n * * set no match (404) and error (500) handlers\n * * configure template engines\n * * store data in locals\n * * listen the http server on a specified port\n *\n * In case you use TypeScript, you can pass custom types to this class because it is also a generic class.\n *\n * Example:\n *\n * ```ts\n * interface CoolReq extends Request {\n * genericsAreDope: boolean\n * }\n *\n * const app = App<any, CoolReq, Response>()\n * ```\n */\nexport class App<Req extends Request = Request, Res extends Response = Response> extends Router<App, Req, Res> {\n middleware: Middleware<Req, Res>[] = []\n locals: Record<string, unknown> = {}\n noMatchHandler: Handler\n onError: ErrorHandler\n settings: AppSettings\n engines: Record<string, TemplateEngine> = {}\n applyExtensions: (req: Request, res: Response, next: NextFunction) => void\n attach: (req: Req, res: Res) => void\n cache: Record<string, unknown>\n\n constructor(options: AppConstructor<Req, Res> = {}) {\n super()\n this.onError = options?.onError || onErrorHandler\n this.noMatchHandler = options?.noMatchHandler || this.onError.bind(this, { code: 404 })\n this.settings = {\n view: View,\n xPoweredBy: true,\n views: `${process.cwd()}/views`,\n 'view cache': process.env.NODE_ENV === 'production',\n 'trust proxy': 0,\n ...options.settings\n }\n this.applyExtensions = options?.applyExtensions\n this.attach = (req, res) => setImmediate(this.handler.bind(this, req, res, undefined), req, res)\n this.cache = {}\n }\n\n /**\n * Set app setting\n * @param setting setting name\n * @param value setting value\n */\n set<K extends keyof AppSettings>(setting: K, value: AppSettings[K]): this {\n this.settings[setting] = value\n\n return this\n }\n\n /**\n * Enable app setting\n * @param setting Setting name\n */\n enable<K extends keyof AppSettings>(setting: K): this {\n this.settings[setting] = true as AppSettings[K]\n\n return this\n }\n\n /**\n * Check if setting is enabled\n * @param setting Setting name\n * @returns\n */\n enabled<K extends keyof AppSettings>(setting: K): boolean {\n return Boolean(this.settings[setting])\n }\n\n /**\n * Disable app setting\n * @param setting Setting name\n */\n disable<K extends keyof AppSettings>(setting: K): this {\n this.settings[setting] = false as AppSettings[K]\n\n return this\n }\n\n /**\n * Return the app's absolute pathname\n * based on the parent(s) that have\n * mounted it.\n *\n * For example if the application was\n * mounted as `\"/admin\"`, which itself\n * was mounted as `\"/blog\"` then the\n * return value would be `\"/blog/admin\"`.\n *\n */\n path(): string {\n return this.parent ? this.parent.path() + this.mountpath : ''\n }\n\n /**\n * Register a template engine with extension\n */\n engine<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions>(\n ext: string,\n fn: TemplateEngine<RenderOptions>\n ): this {\n this.engines[ext[0] === '.' ? ext : `.${ext}`] = fn\n\n return this\n }\n\n /**\n * Render a template\n * @param file What to render\n * @param data data that is passed to a template\n * @param options Template engine options\n * @param cb Callback that consumes error and html\n */\n render<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions>(\n name: string,\n data: Record<string, unknown> = {},\n options: AppRenderOptions<RenderOptions> = {} as AppRenderOptions<RenderOptions>,\n cb: (err: unknown, html?: unknown) => void = () => {}\n ): void {\n let view: View | undefined\n\n const { _locals, ...opts } = options\n\n let locals = this.locals\n\n if (_locals) locals = { ...locals, ..._locals }\n\n locals = { ...locals, ...data }\n\n if (opts.cache == null) (opts.cache as boolean) = this.enabled('view cache')\n\n if (opts.cache) {\n view = this.cache[name] as View\n }\n\n if (!view) {\n const View = this.settings.view\n view = new View(name, {\n defaultEngine: this.settings['view engine'],\n root: this.settings.views,\n engines: this.engines\n })\n\n if (!view.path) {\n const dirs =\n Array.isArray(view.root) && view.root.length > 1\n ? `directories \"${view.root.slice(0, -1).join('\", \"')}\" or \"${view.root[view.root.length - 1]}\"`\n : `directory \"${view.root}\"`\n const err = new Error(`Failed to lookup view \"${name}\" in views ${dirs}`)\n\n return cb(err)\n }\n\n if (opts.cache) {\n this.cache[name] = view\n }\n }\n\n try {\n view.render(opts, locals, cb)\n } catch (err) {\n cb(err)\n }\n }\n use(...args: UseMethodParams<Req, Res, App>): this {\n const base = args[0]\n\n const fns = args.slice(1).flat()\n\n let pathArray = []\n if (typeof base === 'function' || base instanceof App) {\n fns.unshift(base)\n } else {\n // if base is not an array of paths, then convert it to an array.\n let basePaths = []\n if (Array.isArray(base)) basePaths = [...base]\n else if (typeof base === 'string') basePaths = [base]\n\n basePaths = basePaths.filter((element) => {\n if (typeof element === 'string') {\n pathArray.push(element)\n return false\n }\n return true\n })\n fns.unshift(...basePaths)\n }\n pathArray = pathArray.length ? pathArray.map((path) => lead(path)) : ['/']\n\n const mountpath = pathArray.join(', ')\n let regex: { keys: string[]; pattern: RegExp }\n\n for (const fn of fns) {\n if (fn instanceof App) {\n for (const path of pathArray) {\n regex = rg(path, true)\n fn.mountpath = mountpath\n this.apps[path] = fn\n fn.parent = this\n }\n }\n }\n for (const path of pathArray) {\n const handlerPaths = []\n const handlerFunctions = []\n const handlerPathBase = path === '/' ? '' : lead(path)\n for (const fn of fns) {\n if (fn instanceof App && fn.middleware?.length) {\n for (const mw of fn.middleware) {\n handlerPaths.push(handlerPathBase + lead(mw.path))\n handlerFunctions.push(fn)\n }\n } else {\n handlerPaths.push('')\n handlerFunctions.push(fn)\n }\n }\n pushMiddleware(this.middleware)({\n path,\n regex,\n type: 'mw',\n handler: mount(handlerFunctions[0] as Handler),\n handlers: handlerFunctions.slice(1).map(mount),\n fullPaths: handlerPaths\n })\n }\n\n return this\n }\n\n route(path: string): App {\n const app = new App({ settings: this.settings })\n\n this.use(path, app)\n\n return app\n }\n\n #find(url: string): Middleware<Req, Res>[] {\n return this.middleware.filter((m) => {\n m.regex = m.regex || rg(m.path, m.type === 'mw')\n\n let fullPathRegex: { keys: string[]; pattern: RegExp }\n\n m.fullPath && typeof m.fullPath === 'string'\n ? (fullPathRegex = rg(m.fullPath, m.type === 'mw'))\n : (fullPathRegex = null)\n\n return m.regex.pattern.test(url) && (m.type === 'mw' && fullPathRegex ? fullPathRegex.pattern.test(url) : true)\n })\n }\n\n /**\n * Extends Req / Res objects, pushes 404 and 500 handlers, dispatches middleware\n * @param req Req object\n * @param res Res object\n */\n handler<RenderOptions extends TemplateEngineOptions = TemplateEngineOptions>(\n req: Req,\n res: Res,\n next?: NextFunction\n ): void {\n /* Set X-Powered-By header */\n const { xPoweredBy } = this.settings\n if (xPoweredBy) res.setHeader('X-Powered-By', typeof xPoweredBy === 'string' ? xPoweredBy : 'tinyhttp')\n\n const exts = this.applyExtensions || extendMiddleware<RenderOptions>(this)\n\n req.originalUrl = req.url || req.originalUrl\n\n const pathname = getPathname(req.originalUrl)\n\n const matched = this.#find(pathname)\n\n const mw: Middleware[] = [\n {\n handler: exts,\n type: 'mw',\n path: '/'\n },\n ...matched.filter((x) => req.method === 'HEAD' || (x.method ? x.method === req.method : true))\n ]\n\n if (matched[0] != null) {\n mw.push({\n type: 'mw',\n handler: (req, res, next) => {\n if (req.method === 'HEAD') {\n res.statusCode = 204\n return res.end('')\n }\n next()\n },\n path: '/'\n })\n }\n\n mw.push({\n handler: this.noMatchHandler,\n type: 'mw',\n path: '/'\n })\n\n const handle = (mw: Middleware) => async (req: Req, res: Res, next?: NextFunction) => {\n const { path, handler, regex } = mw\n\n let params: URLParams\n\n try {\n params = regex ? getURLParams(regex, pathname) : {}\n } catch (e) {\n console.error(e)\n if (e instanceof URIError) return res.sendStatus(400)\n throw e\n }\n\n // Warning: users should not use :wild as a pattern\n let prefix = path\n if (regex) {\n for (const key of regex.keys as string[]) {\n if (key === 'wild') {\n prefix = prefix.replace('*', params.wild)\n } else {\n prefix = prefix.replace(`:${key}`, params[key])\n }\n }\n }\n\n req.params = { ...req.params, ...params }\n\n if (mw.type === 'mw') {\n req.url = lead(req.originalUrl.substring(prefix.length))\n }\n\n if (!req.path) req.path = getPathname(req.url)\n\n if (this.settings?.enableReqRoute) req.route = mw\n\n await applyHandler<Req, Res>(handler as unknown as Handler<Req, Res>)(req, res, next)\n }\n\n let idx = 0\n\n const loop = () => res.writableEnded || (idx < mw.length && handle(mw[idx++])(req, res, next))\n\n next = next || ((err) => (err ? this.onError(err, req, res) : loop()))\n\n loop()\n }\n\n /**\n * Creates HTTP server and dispatches middleware\n * @param port server listening port\n * @param Server callback after server starts listening\n * @param host server listening host\n */\n listen(port?: number, cb?: () => void, host?: string): Server {\n return createServer().on('request', this.attach).listen(port, host, cb)\n }\n}\n"],"names":["proxyAddr","View","rg","req","res","next","mw"],"mappings":";;;;;;;;;;AAgBA,MAAM,qBAAqB,CAAC,EAAE,UAA+C,UAA0B;AACrG,QAAM,MAAM,OAAO;AACnB,MAAI,OAAO,UAAU,WAAY,SAAQ,QAAQ,KAAK;AAC/C,SAAA,MAAM,KAAK,CAAC;AACrB;AAEa,MAAA,cAAc,CAAC,KAAc,UAA2B;AACnE,QAAM,QAAQ,OAAO,IAAI,SAAS,MAAM,EAAE;AAE1C,MAAI,CAAC,mBAAmB,KAAK,KAAK,EAAU,QAAA;AAE5C,QAAM,SAAU,IAAI,QAAQ,mBAAmB,KAAgB;AAEzD,QAAA,QAAQ,OAAO,QAAQ,GAAG;AAEzB,SAAA,UAAU,KAAK,OAAO,UAAU,GAAG,KAAK,EAAE,KAAA,IAAS,OAAO,KAAK;AACxE;AAEa,MAAA,cAAc,CAAC,KAAc,UAAqC;AACzE,MAAA,OAAe,IAAI,IAAI,kBAAkB;AAEzC,MAAA,CAAC,QAAQ,CAAC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G;AAE7C,WAAI,UAAK,aAAL,mBAAe,eAAgBA,MAAI,QAAQG;AAE/C,YAAM,aAAuB,OAAuC,EAAEH,MAAKC,MAAKC,KAAI;AAAA,IAAA;AAGtF,QAAI,MAAM;AAEV,UAAM,OAAO,MAAM,IAAI,iBAAkB,MAAM,GAAG,UAAU,OAAO,GAAG,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI;AAErF,WAAA,SAAS,CAAC,QAAS,MAAM,KAAK,QAAQ,KAAK,KAAK,GAAG,IAAI,KAAK;AAE9D;EACP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,MAAe,IAAiB,MAAuB;AACrD,WAAA,aAAe,EAAA,GAAG,WAAW,KAAK,MAAM,EAAE,OAAO,MAAM,MAAM,EAAE;AAAA,EACxE;AACF;"}
|
package/dist/onError.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { NextFunction } from '@tinyhttp/router';
|
|
2
|
+
import { App } from './app.js';
|
|
3
|
+
import { Request } from './request.js';
|
|
4
|
+
import { Response } from './response.js';
|
|
5
|
+
|
|
5
6
|
export type ErrorHandler = (this: App, err: any, req: Request, res: Response, next?: NextFunction) => void;
|
|
6
7
|
export declare const onErrorHandler: ErrorHandler;
|
|
7
8
|
//# sourceMappingURL=onError.d.ts.map
|
package/dist/onError.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onError.d.ts","sourceRoot":"","sources":["../src/onError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onError.d.ts","sourceRoot":"","sources":["../src/onError.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,YAAY,KAAK,IAAI,CAAA;AAE1G,eAAO,MAAM,cAAc,EAAE,YAU5B,CAAA"}
|
package/dist/request.d.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
/// <reference types="node" />
|
|
5
1
|
import { IncomingMessage } from 'node:http';
|
|
6
|
-
import
|
|
2
|
+
import { ParsedUrlQuery } from 'node:querystring';
|
|
3
|
+
import { Trust } from '@tinyhttp/proxy-addr';
|
|
7
4
|
import { Options, Ranges } from 'header-range-parser';
|
|
5
|
+
import { Middleware } from '@tinyhttp/router';
|
|
8
6
|
import { App } from './app.js';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
|
|
7
|
+
import { Socket } from 'node:net';
|
|
8
|
+
import { TLSSocket } from 'node:tls';
|
|
9
|
+
import { URLParams } from '@tinyhttp/req';
|
|
10
|
+
|
|
13
11
|
export { getURLParams } from '@tinyhttp/req';
|
|
14
|
-
export declare const getProtocol: (req: Request) => Protocol;
|
|
15
|
-
export declare const getHostname: (req: Request) => string | undefined;
|
|
16
|
-
export declare const getIP: (req: Pick<Request,
|
|
17
|
-
export declare const getIPs: (req: Pick<Request,
|
|
18
|
-
export declare const getSubdomains: (req: Request, subdomainOffset?: number) => string[];
|
|
12
|
+
export declare const getProtocol: (req: Request, trust: Trust) => Protocol;
|
|
13
|
+
export declare const getHostname: (req: Request, trust: Trust) => string | undefined;
|
|
14
|
+
export declare const getIP: (req: Pick<Request, "headers" | "connection" | "socket">, trust: Trust) => string | undefined;
|
|
15
|
+
export declare const getIPs: (req: Pick<Request, "headers" | "connection" | "socket">, trust: Trust) => string[] | undefined;
|
|
16
|
+
export declare const getSubdomains: (req: Request, trust: Trust, subdomainOffset?: number) => string[];
|
|
19
17
|
export type Connection = IncomingMessage['socket'] & {
|
|
20
18
|
encrypted: boolean;
|
|
21
19
|
};
|
package/dist/request.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtD,OAAO,EAAE,KAAK,KAAK,EAAwC,MAAM,sBAAsB,CAAA;AACvF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAGnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAQ5C,eAAO,MAAM,WAAW,QAAS,OAAO,SAAS,KAAK,KAAG,QAUxD,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,OAAO,SAAS,KAAK,KAAG,MAAM,GAAG,SAWjE,CAAA;AAED,eAAO,MAAM,KAAK,QAAS,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,YAAY,GAAG,QAAQ,CAAC,SAAS,KAAK,KAAG,MA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C,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,GAAG,SAAS,CAAA;IAC7E,OAAO,EAAE,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,KAAK,cAAc,CAAA;IAC/C,gBAAgB,EAAE,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,KAAK,cAAc,CAAA;IAC5D,eAAe,EAAE,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,KAAK,cAAc,CAAA;IAC1D,gBAAgB,EAAE,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,KAAK,cAAc,CAAA;IAC5D,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAA;IACnC,OAAO,CAAC,EAAE,GAAG,CAAA;IACb,aAAa,CAAC,EAAE,GAAG,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,GAAG,CAAC,EAAE,GAAG,CAAA;CACV"}
|
package/dist/response.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { ServerResponse } from 'node:http';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
2
|
+
import { SerializeOptions } from '@tinyhttp/cookie';
|
|
3
|
+
import { DownloadOptions, FormatProps, ReadStreamOptions } from '@tinyhttp/res';
|
|
5
4
|
import { App } from './app.js';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
5
|
+
import { Request } from './request.js';
|
|
6
|
+
import { AppRenderOptions, TemplateEngineOptions } from './types.js';
|
|
7
|
+
|
|
8
8
|
export declare const renderTemplate: <O extends TemplateEngineOptions = TemplateEngineOptions>(_req: Request, res: Response, app: App) => (file: string, data?: Record<string, unknown>, options?: AppRenderOptions<O>) => Response;
|
|
9
9
|
export interface Response<B = unknown> extends ServerResponse {
|
|
10
10
|
header(field: string | Record<string, unknown>, val?: string | any[]): Response<B>;
|
package/dist/response.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACpF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEzE,eAAO,MAAM,cAAc,GACxB,CAAC,SAAS,qBAAqB,gCAAgC,OAAO,OAAO,QAAQ,OAAO,GAAG,YACzF,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,gBAAgB,CAAC,CAAC,CAAC,KAAG,QAM9E,CAAA;AAEH,MAAM,WAAW,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,cAAc;IAC3D,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAClF,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC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AAC,EAC1B,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC5B,QAAQ,CAAC,CAAC,CAAC,CAAA;IACd,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAChC,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IACnD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC9G,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC1C,GAAG,CAAC,EAAE,GAAG,CAAA;IACT,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAE5B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;CAC/C"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { Trust } from '@tinyhttp/proxy-addr';
|
|
2
|
+
import { Handler, NextFunction } from '@tinyhttp/router';
|
|
3
|
+
import { ErrorHandler } from './onError.js';
|
|
4
|
+
import { Request } from './request.js';
|
|
5
|
+
import { Response } from './response.js';
|
|
6
|
+
import { View } from './view.js';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* tinyhttp App has a few settings for toggling features
|
|
8
10
|
*/
|
|
@@ -16,6 +18,7 @@ export type AppSettings = Partial<{
|
|
|
16
18
|
view: typeof View;
|
|
17
19
|
'view cache': boolean;
|
|
18
20
|
'view engine': string;
|
|
21
|
+
'trust proxy': Trust;
|
|
19
22
|
}>;
|
|
20
23
|
export type TemplateEngineOptions = {
|
|
21
24
|
[key: string]: unknown;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;IAChC,iBAAiB,EAAE,OAAO,CAAA;IAC1B,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,OAAO,CAAA;IACxB,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;IAC5B,cAAc,EAAE,OAAO,CAAA;IACvB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACxB,IAAI,EAAE,OAAO,IAAI,CAAA;IACjB,YAAY,EAAE,OAAO,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EA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OAAO,CAAC;IACN,KAAK,EAAE,OAAO,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAC,CAAA;AAEJ,MAAM,MAAM,cAAc,CAAC,GAAG,SAAS,OAAO,GAAG,OAAO,EAAE,GAAG,SAAS,QAAQ,GAAG,QAAQ,IAAI,OAAO,CAAC;IACnG,cAAc,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACjC,OAAO,EAAE,YAAY,CAAA;IACrB,QAAQ,EAAE,WAAW,CAAA;IACrB,eAAe,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAA;CAC3E,CAAC,CAAA"}
|
package/dist/view.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* express
|
|
4
|
-
* Copyright(c) 2009-2013 TJ Holowaychuk
|
|
5
|
-
* Copyright(c) 2013 Roman Shtylman
|
|
6
|
-
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
7
|
-
* MIT Licensed
|
|
8
|
-
*/
|
|
9
|
-
import { TemplateEngineOptions, TemplateEngine } from './types.js';
|
|
1
|
+
import { TemplateEngine, TemplateEngineOptions } from './types.js';
|
|
2
|
+
|
|
10
3
|
/**
|
|
11
4
|
* Initialize a new `View` with the given `name`.
|
|
12
5
|
*
|
package/dist/view.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAUvE;;;;;;;;;;;;GAYG;AAEH,qBAAa,IAAI,CAAC,aAAa,SAAS,qBAAqB,GAAG,qBAAqB;;IACnF,GAAG,EAAE,MAAM,CAAA;IACX,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,cAAc,CAAC,aAAa,CAAC,CAAA;IACrC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;gBAErB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,OAAO,CAAC;QACZ,aAAa,EAAE,MAAM,CAAA;QACrB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;QACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC,CAAA;KACvD,CAAM;IA4DT,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI;CAG7G"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinyhttp/app",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
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",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"header-range-parser": "1.1.3",
|
|
36
|
-
"regexparam": "^2.0.
|
|
37
|
-
"@tinyhttp/cookie": "2.1.
|
|
38
|
-
"@tinyhttp/res": "2.2.
|
|
39
|
-
"@tinyhttp/
|
|
40
|
-
"@tinyhttp/req": "2.2.
|
|
41
|
-
"@tinyhttp/
|
|
36
|
+
"regexparam": "^2.0.2",
|
|
37
|
+
"@tinyhttp/cookie": "2.1.1",
|
|
38
|
+
"@tinyhttp/res": "2.2.3",
|
|
39
|
+
"@tinyhttp/router": "2.2.2",
|
|
40
|
+
"@tinyhttp/req": "2.2.3",
|
|
41
|
+
"@tinyhttp/proxy-addr": "2.2.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"dev": "vite",
|