@tinyhttp/app 2.0.11 → 2.0.16
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 +24 -36
- package/package.json +8 -7
package/dist/index.js
CHANGED
|
@@ -223,12 +223,11 @@ class App extends Router {
|
|
|
223
223
|
var _a;
|
|
224
224
|
const base = args[0];
|
|
225
225
|
const fns = args.slice(1).flat();
|
|
226
|
-
if (base instanceof App) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
base
|
|
231
|
-
this.apps['/'] = base;
|
|
226
|
+
if (typeof base === 'function' || base instanceof App) {
|
|
227
|
+
fns.unshift(base);
|
|
228
|
+
}
|
|
229
|
+
else if (Array.isArray(base)) {
|
|
230
|
+
fns.unshift(...base);
|
|
232
231
|
}
|
|
233
232
|
const path = typeof base === 'string' ? base : '/';
|
|
234
233
|
let regex;
|
|
@@ -240,40 +239,29 @@ class App extends Router {
|
|
|
240
239
|
fn.parent = this;
|
|
241
240
|
}
|
|
242
241
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
else if (Array.isArray(base)) {
|
|
251
|
-
super.use('/', [...base, ...fns].map(mount));
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
const handlerPaths = [];
|
|
255
|
-
const handlerFunctions = [];
|
|
256
|
-
for (const fn of fns) {
|
|
257
|
-
if (fn instanceof App && ((_a = fn.middleware) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
258
|
-
for (const mw of fn.middleware) {
|
|
259
|
-
handlerPaths.push(lead(base) + lead(mw.path));
|
|
260
|
-
handlerFunctions.push(fn);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
handlerPaths.push('');
|
|
242
|
+
const handlerPaths = [];
|
|
243
|
+
const handlerFunctions = [];
|
|
244
|
+
const handlerPathBase = path === '/' ? '' : lead(path);
|
|
245
|
+
for (const fn of fns) {
|
|
246
|
+
if (fn instanceof App && ((_a = fn.middleware) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
247
|
+
for (const mw of fn.middleware) {
|
|
248
|
+
handlerPaths.push(handlerPathBase + lead(mw.path));
|
|
265
249
|
handlerFunctions.push(fn);
|
|
266
250
|
}
|
|
267
251
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
handler: mount(handlerFunctions[0]),
|
|
273
|
-
handlers: handlerFunctions.slice(1).map(mount),
|
|
274
|
-
fullPaths: handlerPaths
|
|
275
|
-
});
|
|
252
|
+
else {
|
|
253
|
+
handlerPaths.push('');
|
|
254
|
+
handlerFunctions.push(fn);
|
|
255
|
+
}
|
|
276
256
|
}
|
|
257
|
+
pushMiddleware(this.middleware)({
|
|
258
|
+
path,
|
|
259
|
+
regex,
|
|
260
|
+
type: 'mw',
|
|
261
|
+
handler: mount(handlerFunctions[0]),
|
|
262
|
+
handlers: handlerFunctions.slice(1).map(mount),
|
|
263
|
+
fullPaths: handlerPaths
|
|
264
|
+
});
|
|
277
265
|
return this;
|
|
278
266
|
}
|
|
279
267
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinyhttp/app",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
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,14 +33,15 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@tinyhttp/cookie": "2.0.3",
|
|
36
|
-
"@tinyhttp/proxy-addr": "2.0.
|
|
37
|
-
"@tinyhttp/req": "2.0.
|
|
38
|
-
"@tinyhttp/res": "2.0.
|
|
39
|
-
"@tinyhttp/router": "2.0.
|
|
40
|
-
"header-range-parser": "
|
|
36
|
+
"@tinyhttp/proxy-addr": "2.0.3",
|
|
37
|
+
"@tinyhttp/req": "2.0.11",
|
|
38
|
+
"@tinyhttp/res": "2.0.12",
|
|
39
|
+
"@tinyhttp/router": "2.0.4",
|
|
40
|
+
"header-range-parser": "1.1.1",
|
|
41
41
|
"regexparam": "^2.0.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "rollup -c"
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
|
+
"readme": "# @tinyhttp/app\n\nThe core of tinyhttp. Contains the `App`, `Request` and `Response`. Additionally, it provides special tinyhttp-specific types.\n\n## Install\n\n```sh\npnpm i @tinyhttp/app\n```\n\n## Example\n\n```ts\nimport { App } from '@tinyhttp/app'\nimport type { Request, Response, NextFunction } from '@tinyhttp/app'\n\nnew App()\n .use((req: Request, res: Response, next: NextFunction) => {\n console.log('Did a request')\n next()\n })\n .get('/', (_, res) => res.send('<h1>Hello World</h1>'))\n .get('/page/:page', (req, res) => res.send(`You opened ${req.params.page}`))\n .listen(3000)\n```\n"
|
|
46
47
|
}
|