Socket
Socket
Sign inDemoInstall

@tinyhttp/app

Package Overview
Dependencies
Maintainers
1
Versions
305
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/app - npm Package Compare versions

Comparing version 2.2.4 to 2.3.0

40

dist/index.js

@@ -6,15 +6,15 @@ import { STATUS_CODES, createServer } from "node:http";

import { parse } from "regexparam";
import { proxyaddr, all, compile } from "@tinyhttp/proxy-addr";
import { getResponseHeader, setHeader, send, json, status, sendStatus, sendFile, setContentType, setLocationHeader, setLinksHeader, setVaryHeader, setCookie, clearCookie, formatResponse, redirect, attachment, download, append } from "@tinyhttp/res";
import { proxyaddr, all, compile } from "@tinyhttp/proxy-addr";
import { isIP } from "node:net";
import { statSync } from "node:fs";
import { extname, resolve, dirname, basename, join } from "node:path";
const trustRemoteAddress = ({ socket }) => {
const trustRemoteAddress = ({ socket }, trust) => {
const val = socket.remoteAddress;
if (typeof val === "string") return compile(val.split(",").map((x) => x.trim()));
return compile(val || []);
if (typeof trust !== "function") trust = compile(trust);
return trust(val, 0);
};
const getProtocol = (req) => {
const getProtocol = (req, trust) => {
const proto = `http${req.secure ? "s" : ""}`;
if (!trustRemoteAddress(req)) return proto;
if (!trustRemoteAddress(req, trust)) return proto;
const header = req.headers["X-Forwarded-Proto"] || proto;

@@ -24,5 +24,5 @@ const index = header.indexOf(",");

};
const getHostname = (req) => {
const getHostname = (req, trust) => {
let host = req.get("X-Forwarded-Host");
if (!host || !trustRemoteAddress(req)) host = req.get("Host");
if (!host || !trustRemoteAddress(req, trust)) host = req.get("Host");
if (!host) return;

@@ -32,6 +32,6 @@ const index = host.indexOf(":", host[0] === "[" ? host.indexOf("]") + 1 : 0);

};
const getIP = (req) => proxyaddr(req, trustRemoteAddress(req)).replace(/^.*:/, "");
const getIPs = (req) => all(req, trustRemoteAddress(req));
const getSubdomains = (req, subdomainOffset = 2) => {
const hostname = getHostname(req);
const getIP = (req, trust) => proxyaddr(req, trust).replace(/^.*:/, "");
const getIPs = (req, trust) => all(req, trust);
const getSubdomains = (req, trust, subdomainOffset = 2) => {
const hostname = getHostname(req, trust);
if (!hostname) return [];

@@ -56,9 +56,14 @@ const subdomains = isIP(hostname) ? [hostname] : hostname.split(".").reverse();

}
let trust = settings == null ? void 0 : settings["trust proxy"];
if (typeof trust !== "function") {
trust = compile(trust);
settings["trust proxy"] = trust;
}
if (settings == null ? void 0 : settings.networkExtensions) {
req.protocol = getProtocol(req);
req.protocol = getProtocol(req, trust);
req.secure = req.protocol === "https";
req.hostname = getHostname(req);
req.subdomains = getSubdomains(req, settings.subdomainOffset);
req.ip = getIP(req);
req.ips = getIPs(req);
req.hostname = getHostname(req, trust);
req.subdomains = getSubdomains(req, trust, settings.subdomainOffset);
req.ip = getIP(req, trust);
req.ips = getIPs(req, trust);
}

@@ -180,2 +185,3 @@ req.query = getQueryParams(req.url);

"view cache": process.env.NODE_ENV === "production",
"trust proxy": 0,
...options.settings

@@ -182,0 +188,0 @@ };

import { IncomingMessage } from 'node:http';
import { ParsedUrlQuery } from 'node:querystring';
import { Trust } from '@tinyhttp/proxy-addr';
import { Options, Ranges } from 'header-range-parser';

@@ -11,7 +12,7 @@ import { Middleware } from '@tinyhttp/router';

export { getURLParams } from '@tinyhttp/req';
export declare const getProtocol: (req: Request) => Protocol;
export declare const getHostname: (req: Request) => string | undefined;
export declare const getIP: (req: Pick<Request, "headers" | "connection" | "socket">) => string | undefined;
export declare const getIPs: (req: Pick<Request, "headers" | "connection" | "socket">) => string[] | undefined;
export declare const getSubdomains: (req: Request, subdomainOffset?: number) => string[];
export declare const getProtocol: (req: Request, trust: Trust) => Protocol;
export declare const getHostname: (req: Request, trust: Trust) => string | undefined;
export declare const getIP: (req: Pick<Request, "headers" | "connection" | "socket">, trust: Trust) => string | undefined;
export declare const getIPs: (req: Pick<Request, "headers" | "connection" | "socket">, trust: Trust) => string[] | undefined;
export declare const getSubdomains: (req: Request, trust: Trust, subdomainOffset?: number) => string[];
export type Connection = IncomingMessage['socket'] & {

@@ -18,0 +19,0 @@ encrypted: boolean;

@@ -0,1 +1,2 @@

import { Trust } from '@tinyhttp/proxy-addr';
import { Handler, NextFunction } from '@tinyhttp/router';

@@ -20,2 +21,3 @@ import { ErrorHandler } from './onError.js';

'view engine': string;
'trust proxy': Trust;
}>;

@@ -22,0 +24,0 @@ export type TemplateEngineOptions = {

{
"name": "@tinyhttp/app",
"version": "2.2.4",
"version": "2.3.0",
"description": "0-legacy, tiny & fast web framework as a replacement of Express",

@@ -38,6 +38,6 @@ "type": "module",

"@tinyhttp/cookie": "2.1.1",
"@tinyhttp/proxy-addr": "2.1.4",
"@tinyhttp/res": "2.2.3",
"@tinyhttp/router": "2.2.2",
"@tinyhttp/req": "2.2.3",
"@tinyhttp/res": "2.2.3",
"@tinyhttp/router": "2.2.2"
"@tinyhttp/proxy-addr": "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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc