@tinyhttp/app
Advanced tools
Comparing version 2.0.34 to 2.1.0
/// <reference types="node/http.js" /> | ||
import { Server } from 'http'; | ||
import { Server } from 'node:http'; | ||
import type { Request } from './request.js'; | ||
@@ -4,0 +4,0 @@ import type { Response } from './response.js'; |
@@ -1,5 +0,19 @@ | ||
import { STATUS_CODES, createServer } from "http"; | ||
import path from "path"; | ||
var __accessCheck = (obj, member, msg) => { | ||
if (!member.has(obj)) | ||
throw TypeError("Cannot " + msg); | ||
}; | ||
var __privateAdd = (obj, member, value) => { | ||
if (member.has(obj)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
}; | ||
var __privateMethod = (obj, member, method) => { | ||
__accessCheck(obj, member, "access private method"); | ||
return method; | ||
}; | ||
var _find, find_fn; | ||
import { STATUS_CODES, createServer } from "node:http"; | ||
import path from "node:path"; | ||
import { proxyaddr, all, compile } from "@tinyhttp/proxy-addr"; | ||
import { isIP } from "net"; | ||
import { isIP } from "node:net"; | ||
import { getRequestHeader, getQueryParams, getRangeFromHeader, getAccepts, getAcceptsCharsets, getAcceptsEncodings, getAcceptsLanguages, checkIfXMLHttpRequest, getFreshOrStale, getPathname, getURLParams } from "@tinyhttp/req"; | ||
@@ -24,3 +38,3 @@ import { getURLParams as getURLParams2 } from "@tinyhttp/req"; | ||
const getProtocol = (req) => { | ||
const proto = req.connection.encrypted ? "https" : "http"; | ||
const proto = `http${req.connection.encrypted ? "s" : ""}`; | ||
if (!trustRemoteAddress(req)) | ||
@@ -135,5 +149,6 @@ return proto; | ||
}; | ||
class App extends Router { | ||
const _App = class extends Router { | ||
constructor(options = {}) { | ||
super(); | ||
__privateAdd(this, _find); | ||
this.middleware = []; | ||
@@ -198,3 +213,3 @@ this.locals = {}; | ||
const fns = args.slice(1).flat(); | ||
if (typeof base === "function" || base instanceof App) { | ||
if (typeof base === "function" || base instanceof _App) { | ||
fns.unshift(base); | ||
@@ -207,3 +222,3 @@ } else if (Array.isArray(base)) { | ||
for (const fn of fns) { | ||
if (fn instanceof App) { | ||
if (fn instanceof _App) { | ||
regex = parse(path2, true); | ||
@@ -219,3 +234,3 @@ fn.mountpath = path2; | ||
for (const fn of fns) { | ||
if (fn instanceof App && ((_a = fn.middleware) == null ? void 0 : _a.length)) { | ||
if (fn instanceof _App && ((_a = fn.middleware) == null ? void 0 : _a.length)) { | ||
for (const mw of fn.middleware) { | ||
@@ -248,14 +263,6 @@ handlerPaths.push(handlerPathBase + lead(mw.path)); | ||
route(path2) { | ||
const app = new App(); | ||
const app = new _App(); | ||
this.use(path2, app); | ||
return app; | ||
} | ||
#find(url) { | ||
return this.middleware.filter((m) => { | ||
m.regex = m.regex || parse(m.path, m.type === "mw"); | ||
let fullPathRegex; | ||
m.fullPath && typeof m.fullPath === "string" ? fullPathRegex = parse(m.fullPath, m.type === "mw") : fullPathRegex = null; | ||
return m.regex.pattern.test(url) && (m.type === "mw" && fullPathRegex ? fullPathRegex.pattern.test(url) : true); | ||
}); | ||
} | ||
/** | ||
@@ -273,3 +280,3 @@ * Extends Req / Res objects, pushes 404 and 500 handlers, dispatches middleware | ||
const pathname = getPathname(req.originalUrl); | ||
const matched = this.#find(pathname); | ||
const matched = __privateMethod(this, _find, find_fn).call(this, pathname); | ||
const mw = [ | ||
@@ -333,3 +340,13 @@ { | ||
} | ||
} | ||
}; | ||
let App = _App; | ||
_find = new WeakSet(); | ||
find_fn = function(url) { | ||
return this.middleware.filter((m) => { | ||
m.regex = m.regex || parse(m.path, m.type === "mw"); | ||
let fullPathRegex; | ||
m.fullPath && typeof m.fullPath === "string" ? fullPathRegex = parse(m.fullPath, m.type === "mw") : fullPathRegex = null; | ||
return m.regex.pattern.test(url) && (m.type === "mw" && fullPathRegex ? fullPathRegex.pattern.test(url) : true); | ||
}); | ||
}; | ||
export { | ||
@@ -336,0 +353,0 @@ App, |
/// <reference types="node/http.js" /> | ||
import { IncomingMessage } from 'http'; | ||
import { ParsedUrlQuery } from 'querystring'; | ||
import { IncomingMessage } from 'node:http'; | ||
import type { ParsedUrlQuery } from 'node:querystring'; | ||
import { Options, Ranges } from 'header-range-parser'; | ||
@@ -9,4 +9,4 @@ import { App } from './app.js'; | ||
import type { URLParams } from '@tinyhttp/req'; | ||
import type { Socket } from 'net'; | ||
import type { TLSSocket } from 'tls'; | ||
import type { Socket } from 'node:net'; | ||
import type { TLSSocket } from 'node:tls'; | ||
export { getURLParams } from '@tinyhttp/req'; | ||
@@ -22,3 +22,3 @@ export declare const getRouteFromApp: ({ middleware }: App, h: Handler<Request, Response>) => Middleware<Request, Response>; | ||
}; | ||
export type Protocol = 'http' | 'https' | string; | ||
export type Protocol = 'node:http' | 'https' | string; | ||
export type { URLParams }; | ||
@@ -25,0 +25,0 @@ type AcceptsReturns = string | boolean | string[]; |
/// <reference types="node/http.js" /> | ||
import { ServerResponse } from 'http'; | ||
import { ServerResponse } from 'node:http'; | ||
import type { SerializeOptions } from '@tinyhttp/cookie'; | ||
@@ -4,0 +4,0 @@ import { Request } from './request.js'; |
{ | ||
"name": "@tinyhttp/app", | ||
"version": "2.0.34", | ||
"version": "2.1.0", | ||
"description": "0-legacy, tiny & fast web framework as a replacement of Express", | ||
@@ -37,7 +37,7 @@ "type": "module", | ||
"regexparam": "^2.0.1", | ||
"@tinyhttp/cookie": "2.0.7", | ||
"@tinyhttp/proxy-addr": "2.0.8", | ||
"@tinyhttp/req": "2.0.17", | ||
"@tinyhttp/res": "2.0.24", | ||
"@tinyhttp/router": "2.1.1" | ||
"@tinyhttp/cookie": "2.1.0", | ||
"@tinyhttp/proxy-addr": "2.1.0", | ||
"@tinyhttp/req": "2.1.0", | ||
"@tinyhttp/res": "2.1.0", | ||
"@tinyhttp/router": "2.2.0" | ||
}, | ||
@@ -44,0 +44,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
34982
597
0
+ Added@tinyhttp/accepts@2.1.0(transitive)
+ Added@tinyhttp/content-disposition@2.1.0(transitive)
+ Added@tinyhttp/cookie@2.1.0(transitive)
+ Added@tinyhttp/cookie-signature@2.1.0(transitive)
+ Added@tinyhttp/encode-url@2.1.0(transitive)
+ Added@tinyhttp/etag@2.1.0(transitive)
+ Added@tinyhttp/forwarded@2.1.0(transitive)
+ Added@tinyhttp/proxy-addr@2.1.0(transitive)
+ Added@tinyhttp/req@2.1.0(transitive)
+ Added@tinyhttp/res@2.1.0(transitive)
+ Added@tinyhttp/router@2.2.0(transitive)
+ Added@tinyhttp/send@2.1.0(transitive)
+ Added@tinyhttp/type-is@2.1.0(transitive)
+ Added@tinyhttp/url@2.1.0(transitive)
- Removed@tinyhttp/accepts@2.0.9(transitive)
- Removed@tinyhttp/content-disposition@2.0.10(transitive)
- Removed@tinyhttp/cookie@2.0.7(transitive)
- Removed@tinyhttp/cookie-signature@2.0.7(transitive)
- Removed@tinyhttp/encode-url@2.0.8(transitive)
- Removed@tinyhttp/etag@2.0.7(transitive)
- Removed@tinyhttp/forwarded@2.0.7(transitive)
- Removed@tinyhttp/proxy-addr@2.0.8(transitive)
- Removed@tinyhttp/req@2.0.17(transitive)
- Removed@tinyhttp/res@2.0.24(transitive)
- Removed@tinyhttp/router@2.1.1(transitive)
- Removed@tinyhttp/send@2.0.9(transitive)
- Removed@tinyhttp/type-is@2.0.8(transitive)
- Removed@tinyhttp/url@2.0.9(transitive)
Updated@tinyhttp/cookie@2.1.0
Updated@tinyhttp/proxy-addr@2.1.0
Updated@tinyhttp/req@2.1.0
Updated@tinyhttp/res@2.1.0
Updated@tinyhttp/router@2.2.0