@tinyhttp/app
Advanced tools
Comparing version 2.0.11 to 2.0.12
@@ -226,9 +226,8 @@ import { STATUS_CODES, createServer } from 'http'; | ||
const fns = args.slice(1).flat(); | ||
if (base instanceof App) { | ||
// Set App parent to current App | ||
base.parent = this; | ||
// Mount on root | ||
base.mountpath = '/'; | ||
this.apps['/'] = base; | ||
if (typeof base === 'function' || base instanceof App) { | ||
fns.unshift(base); | ||
} | ||
else if (Array.isArray(base)) { | ||
fns.unshift(...base); | ||
} | ||
const path = typeof base === 'string' ? base : '/'; | ||
@@ -244,36 +243,25 @@ let regex; | ||
} | ||
if (base === '/') { | ||
for (const fn of fns) | ||
super.use(base, mount(fn)); | ||
} | ||
else if (typeof base === 'function' || base instanceof App) { | ||
super.use('/', [base, ...fns].map(mount)); | ||
} | ||
else if (Array.isArray(base)) { | ||
super.use('/', [...base, ...fns].map(mount)); | ||
} | ||
else { | ||
const handlerPaths = []; | ||
const handlerFunctions = []; | ||
for (const fn of fns) { | ||
if (fn instanceof App && ((_a = fn.middleware) === null || _a === void 0 ? void 0 : _a.length)) { | ||
for (const mw of fn.middleware) { | ||
handlerPaths.push(lead(base) + lead(mw.path)); | ||
handlerFunctions.push(fn); | ||
} | ||
} | ||
else { | ||
handlerPaths.push(''); | ||
const handlerPaths = []; | ||
const handlerFunctions = []; | ||
const handlerPathBase = path === '/' ? '' : lead(path); | ||
for (const fn of fns) { | ||
if (fn instanceof App && ((_a = fn.middleware) === null || _a === void 0 ? void 0 : _a.length)) { | ||
for (const mw of fn.middleware) { | ||
handlerPaths.push(handlerPathBase + lead(mw.path)); | ||
handlerFunctions.push(fn); | ||
} | ||
} | ||
pushMiddleware(this.middleware)({ | ||
path: base, | ||
regex, | ||
type: 'mw', | ||
handler: mount(handlerFunctions[0]), | ||
handlers: handlerFunctions.slice(1).map(mount), | ||
fullPaths: handlerPaths | ||
}); | ||
else { | ||
handlerPaths.push(''); | ||
handlerFunctions.push(fn); | ||
} | ||
} | ||
pushMiddleware(this.middleware)({ | ||
path, | ||
regex, | ||
type: 'mw', | ||
handler: mount(handlerFunctions[0]), | ||
handlers: handlerFunctions.slice(1).map(mount), | ||
fullPaths: handlerPaths | ||
}); | ||
return this; | ||
@@ -280,0 +268,0 @@ } |
{ | ||
"name": "@tinyhttp/app", | ||
"version": "2.0.11", | ||
"version": "2.0.12", | ||
"description": "0-legacy, tiny & fast web framework as a replacement of Express", | ||
@@ -39,3 +39,3 @@ "type": "module", | ||
"@tinyhttp/res": "2.0.9", | ||
"@tinyhttp/router": "2.0.3", | ||
"@tinyhttp/router": "2.0.4", | ||
"header-range-parser": "^1.1.1", | ||
@@ -42,0 +42,0 @@ "regexparam": "^2.0.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25977
594
+ Added@tinyhttp/router@2.0.4(transitive)
- Removed@tinyhttp/router@2.0.3(transitive)
Updated@tinyhttp/router@2.0.4