ios-dev/comments/Home/node_modules/@tinyhttp/app/dist/index.js.map

1 line
34 KiB
Plaintext
Raw Permalink Normal View History

2024-03-11 14:47:28 +03:00
{"version":3,"file":"index.js","sources":["../src/request.ts","../src/onError.ts","../src/response.ts","../src/extend.ts","../src/view.ts","../src/app.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http'\nimport type { ParsedUrlQuery } from 'node:querystring'\n\nimport { Options, Ranges } from 'header-range-parser'\nimport { proxyaddr as proxyAddr, all, compile } from '@tinyhttp/proxy-addr'\n\nimport { App } from './app.js'\nimport type { Middleware } from '@tinyhttp/router'\n\nimport type { URLParams } from '@tinyhttp/req'\nimport { isIP } from 'node:net'\nimport type { Socket } from 'node:net'\nimport type { TLSSocket } from 'node:tls'\n\nexport { getURLParams } from '@tinyhttp/req'\n\nconst trustRemoteAddress = ({ socket }: Pick<Request, 'headers' | 'socket'>) => {\n const val = socket.remoteAddress\n if (typeof val === 'string') return compile(val.split(',').map((x) => x.trim()))\n return compile(val || [])\n}\n\nexport const getProtocol = (req: Request): Protocol => {\n const proto = `http${req.secure ? 's' : ''}`\n\n if (!trustRemoteAddress(req)) return proto\n\n const header = (req.headers['X-Forwarded-Proto'] as string) || proto\n\n const index = header.indexOf(',')\n\n return index !== -1 ? header.substring(0, index).trim() : header.trim()\n}\n\nexport const getHostname = (req: Request): string | undefined => {\n let host: string = req.get('X-Forwarded-Host') as string\n\n if (!host || !trustRemoteAddress(req)) host = req.get('Host') as string\n\n if (!host) return\n\n // IPv6 literal support\n const index = host.indexOf(':', host[0] === '[' ? host.indexOf(']') + 1 : 0)\n\n return index !== -1 ? host.substring(0, index) : host\n}\n\nexport const getIP = (req: Pick<Request, 'headers' | 'connection' | 'socket'>): string | undefined =>\n proxyAddr(req, trustRemoteAddress(req)).replace(/^.*:/, '') // striping the redundant prefix addeded by OS to IPv4 address\n\nexport const getIPs = (req: Pick<Request, 'headers' | 'connection' | 'socket'>): string[] | undefined =>\n all(req, trustRemoteAddress(req))\n\nexport const getSubdomains = (req: Request, subdomainOffset = 2): string[] => {\n const hostname = getHostname(req)\n\n if (!hostname) return []\n\n const subdomains = isIP(hostname) ? [hostname] : hostname.split('.').reverse()\n\n return subdomains.slice(subdomainOffset)\n}\n\nexport type Connection = IncomingMessage['socket'] & {\n encrypted: boolean\n}\n\nexport type Protocol = 'http' | 'https' | string\n\nexport type { URLParams }\n\ntype AcceptsReturns = string | boolean | string[]\n\nexport interface Request extends IncomingMessage {\n originalUrl: string\n path: string\n url: string\n query: ParsedUrlQuery\n params: URLParams\n connection: Connection\n socket: TLSSocket | Socket\n route?: Middleware\n protocol: Protocol\n secure: boolean\n xhr: boolean\n hostname?: string\n ip?: string\n ips?: string[]\n subdomains?: string[]\n get: (header: string) => string | string[] | undefined\n range: (size: number, options?: Options) => -1 | -2 | -3 | Ranges | undefined\n accepts: (...types: string[]) => AcceptsReturns\n acceptsEncodings: (...encodings: string[]) => AcceptsReturns\n acceptsCharsets: (...charsets: string[]) => AcceptsReturns\n acceptsLanguages: (...languages: string[]) => AcceptsReturns\n is: (...types: string[]) => boolean\n cookies?: any\n signedCookies?: any\n secret?: string | string[]\n fresh?: boolean\n stale?: boolean\n body?: any\n app?: App\n}\n","import type { NextFunction } from '@tinyhttp/router'\nimport { STATUS_CODES } from 'node:http'\nimport type { Request } from './request.js'\nimport type { Response } from './response.js'\nimport type { App } from './app.js'\n\nexport type ErrorHandler = (this: App, err: any, req: Request, res: Response, next?: NextFunction) => void\n\nexport const onErrorHandler: ErrorHandler = function (this: App, err: any, _req: Request, res: Response) {\n if (this.onError === onErrorHandler && this.parent) return this.parent.onError(err, _req, res)\n\n if (err instanceof Error) console.error(err)\n\