@tinyhttp/app 2.0.11 → 2.0.12

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.
Files changed (2) hide show
  1. package/dist/index.js +24 -36
  2. package/package.json +2 -2
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
- // Set App parent to current App
228
- base.parent = this;
229
- // Mount on root
230
- base.mountpath = '/';
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
- if (base === '/') {
244
- for (const fn of fns)
245
- super.use(base, mount(fn));
246
- }
247
- else if (typeof base === 'function' || base instanceof App) {
248
- super.use('/', [base, ...fns].map(mount));
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
- pushMiddleware(this.middleware)({
269
- path: base,
270
- regex,
271
- type: 'mw',
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.11",
3
+ "version": "2.0.12",
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",
@@ -36,7 +36,7 @@
36
36
  "@tinyhttp/proxy-addr": "2.0.2",
37
37
  "@tinyhttp/req": "2.0.8",
38
38
  "@tinyhttp/res": "2.0.9",
39
- "@tinyhttp/router": "2.0.3",
39
+ "@tinyhttp/router": "2.0.4",
40
40
  "header-range-parser": "^1.1.1",
41
41
  "regexparam": "^2.0.0"
42
42
  },