Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

46
Frontend-Learner/node_modules/httpxy/LICENSE generated vendored Normal file
View file

@ -0,0 +1,46 @@
MIT License
Copyright (c) Pooya Parsa <pooya@pi0.io>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
----
Based on http-party/node-http-proxy (9b96cd7)
Copyright (c) 2010-2016 Charlie Robbins, Jarrett Cruger & the Contributors.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

76
Frontend-Learner/node_modules/httpxy/README.md generated vendored Normal file
View file

@ -0,0 +1,76 @@
# 🔀 httpxy
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![bundle][bundle-src]][bundle-href]
[![Codecov][codecov-src]][codecov-href]
A Full-Featured HTTP and WebSocket Proxy for Node.js forked from [http-party/node-http-proxy](https://github.com/http-party/node-http-proxy) with modern Typescript rewrite.
## Usage
Install package:
```sh
# npm
npm install httpxy
# yarn
yarn add httpxy
# pnpm
pnpm install httpxy
```
Create proxy:
```ts
import { createServer } from "node:http";
import { createProxyServer } from "httpxy";
const proxy = createProxyServer({});
const server = createServer(async (req, res) => {
try {
await proxy.web(req, res, {
target: address /* address of your proxy server here */,
});
} catch (error) {
console.error(error);
res.statusCode = 500;
res.end("Proxy error: " + error.toString());
}
});
server.listen(3000, () => {
console.log("Proxy is listening on http://localhost:3000");
});
```
Checkout [http-party/node-http-proxy](https://github.com/http-party/node-http-proxy) for more options and examples (note: `followRedirects` is not supported).
## Development
- Clone this repository
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`
## License
Made with 💛
Published under [MIT License](./LICENSE).
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/httpxy?style=flat&colorA=18181B&colorB=F0DB4F
[npm-version-href]: https://npmjs.com/package/httpxy
[npm-downloads-src]: https://img.shields.io/npm/dm/httpxy?style=flat&colorA=18181B&colorB=F0DB4F
[npm-downloads-href]: https://npmjs.com/package/httpxy
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/httpxy/main?style=flat&colorA=18181B&colorB=F0DB4F
[codecov-href]: https://codecov.io/gh/unjs/httpxy
[bundle-src]: https://img.shields.io/bundlephobia/minzip/httpxy?style=flat&colorA=18181B&colorB=F0DB4F
[bundle-href]: https://bundlephobia.com/result?p=httpxy

588
Frontend-Learner/node_modules/httpxy/dist/index.cjs generated vendored Normal file
View file

@ -0,0 +1,588 @@
'use strict';
const http = require('node:http');
const https = require('node:https');
const node_events = require('node:events');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
const http__default = /*#__PURE__*/_interopDefaultCompat(http);
const https__default = /*#__PURE__*/_interopDefaultCompat(https);
const upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
const isSSL = /^https|wss/;
function setupOutgoing(outgoing, options, req, forward) {
outgoing.port = options[forward || "target"].port || (isSSL.test(options[forward || "target"].protocol) ? 443 : 80);
for (const e of [
"host",
"hostname",
"socketPath",
"pfx",
"key",
"passphrase",
"cert",
"ca",
"ciphers",
"secureProtocol"
]) {
outgoing[e] = options[forward || "target"][e];
}
outgoing.method = options.method || req.method;
outgoing.headers = { ...req.headers };
if (options.headers) {
outgoing.headers = { ...outgoing.headers, ...options.headers };
}
if (options.auth) {
outgoing.auth = options.auth;
}
if (options.ca) {
outgoing.ca = options.ca;
}
if (isSSL.test(options[forward || "target"].protocol)) {
outgoing.rejectUnauthorized = options.secure === undefined ? true : options.secure;
}
outgoing.agent = options.agent || false;
outgoing.localAddress = options.localAddress;
if (!outgoing.agent) {
outgoing.headers = outgoing.headers || {};
if (typeof outgoing.headers.connection !== "string" || !upgradeHeader.test(outgoing.headers.connection)) {
outgoing.headers.connection = "close";
}
}
const target = options[forward || "target"];
const targetPath = target && options.prependPath !== false ? target.pathname || target.path || "" : "";
const parsed = new URL(req.url, "http://localhost");
let outgoingPath = options.toProxy ? req.url : parsed.pathname + parsed.search || "";
outgoingPath = options.ignorePath ? "" : outgoingPath;
outgoing.path = joinURL(targetPath, outgoingPath);
if (options.changeOrigin) {
outgoing.headers.host = requiresPort(outgoing.port, options[forward || "target"].protocol) && !hasPort(outgoing.host) ? outgoing.host + ":" + outgoing.port : outgoing.host;
}
return outgoing;
}
function joinURL(base, path) {
if (!base || base === "/") {
return path || "/";
}
if (!path || path === "/") {
return base || "/";
}
const baseHasTrailing = base[base.length - 1] === "/";
const pathHasLeading = path[0] === "/";
if (baseHasTrailing && pathHasLeading) {
return base + path.slice(1);
}
if (!baseHasTrailing && !pathHasLeading) {
return base + "/" + path;
}
return base + path;
}
function setupSocket(socket) {
socket.setTimeout(0);
socket.setNoDelay(true);
socket.setKeepAlive(true, 0);
return socket;
}
function getPort(req) {
const res = req.headers.host ? req.headers.host.match(/:(\d+)/) : "";
if (res) {
return res[1];
}
return hasEncryptedConnection(req) ? "443" : "80";
}
function hasEncryptedConnection(req) {
return Boolean(req.connection.encrypted || req.connection.pair);
}
function rewriteCookieProperty(header, config, property) {
if (Array.isArray(header)) {
return header.map(function(headerElement) {
return rewriteCookieProperty(headerElement, config, property);
});
}
return header.replace(
new RegExp(String.raw`(;\s*` + property + "=)([^;]+)", "i"),
function(match, prefix, previousValue) {
let newValue;
if (previousValue in config) {
newValue = config[previousValue];
} else if ("*" in config) {
newValue = config["*"];
} else {
return match;
}
return newValue ? prefix + newValue : "";
}
);
}
function hasPort(host) {
return !!~host.indexOf(":");
}
function requiresPort(_port, _protocol) {
const protocol = _protocol.split(":")[0];
const port = +_port;
if (!port) return false;
switch (protocol) {
case "http":
case "ws": {
return port !== 80;
}
case "https":
case "wss": {
return port !== 443;
}
case "ftp": {
return port !== 21;
}
case "gopher": {
return port !== 70;
}
case "file": {
return false;
}
}
return port !== 0;
}
function defineProxyMiddleware(m) {
return m;
}
function defineProxyOutgoingMiddleware(m) {
return m;
}
const redirectRegex = /^201|30([1278])$/;
const removeChunked = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
if (req.httpVersion === "1.0") {
delete proxyRes.headers["transfer-encoding"];
}
});
const setConnection = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
if (req.httpVersion === "1.0") {
proxyRes.headers.connection = req.headers.connection || "close";
} else if (req.httpVersion !== "2.0" && !proxyRes.headers.connection) {
proxyRes.headers.connection = req.headers.connection || "keep-alive";
}
});
const setRedirectHostRewrite = defineProxyOutgoingMiddleware(
(req, res, proxyRes, options) => {
if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite) && proxyRes.headers.location && redirectRegex.test(String(proxyRes.statusCode))) {
const target = new URL(options.target);
const u = new URL(proxyRes.headers.location);
if (target.host !== u.host) {
return;
}
if (options.hostRewrite) {
u.host = options.hostRewrite;
} else if (options.autoRewrite) {
u.host = req.headers.host;
}
if (options.protocolRewrite) {
u.protocol = options.protocolRewrite;
}
proxyRes.headers.location = u.toString();
}
}
);
const writeHeaders = defineProxyOutgoingMiddleware(
(req, res, proxyRes, options) => {
let rewriteCookieDomainConfig = options.cookieDomainRewrite;
let rewriteCookiePathConfig = options.cookiePathRewrite;
const preserveHeaderKeyCase = options.preserveHeaderKeyCase;
let rawHeaderKeyMap;
const setHeader = function(key, header) {
if (header === undefined) {
return;
}
if (rewriteCookieDomainConfig && key.toLowerCase() === "set-cookie") {
header = rewriteCookieProperty(
header,
rewriteCookieDomainConfig,
"domain"
);
}
if (rewriteCookiePathConfig && key.toLowerCase() === "set-cookie") {
header = rewriteCookieProperty(header, rewriteCookiePathConfig, "path");
}
res.setHeader(String(key).trim(), header);
};
if (typeof rewriteCookieDomainConfig === "string") {
rewriteCookieDomainConfig = { "*": rewriteCookieDomainConfig };
}
if (typeof rewriteCookiePathConfig === "string") {
rewriteCookiePathConfig = { "*": rewriteCookiePathConfig };
}
if (preserveHeaderKeyCase && proxyRes.rawHeaders !== undefined) {
rawHeaderKeyMap = {};
for (let i = 0; i < proxyRes.rawHeaders.length; i += 2) {
const key = proxyRes.rawHeaders[i];
rawHeaderKeyMap[key.toLowerCase()] = key;
}
}
for (let key of Object.keys(proxyRes.headers)) {
const header = proxyRes.headers[key];
if (preserveHeaderKeyCase && rawHeaderKeyMap) {
key = rawHeaderKeyMap[key] || key;
}
setHeader(key, header);
}
}
);
const writeStatusCode = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
if (proxyRes.statusMessage) {
res.statusCode = proxyRes.statusCode;
res.statusMessage = proxyRes.statusMessage;
} else {
res.statusCode = proxyRes.statusCode;
}
});
const webOutgoingMiddleware = [
removeChunked,
setConnection,
setRedirectHostRewrite,
writeHeaders,
writeStatusCode
];
const nativeAgents = { http: http__default, https: https__default };
const deleteLength = defineProxyMiddleware((req) => {
if ((req.method === "DELETE" || req.method === "OPTIONS") && !req.headers["content-length"]) {
req.headers["content-length"] = "0";
delete req.headers["transfer-encoding"];
}
});
const timeout = defineProxyMiddleware((req, res, options) => {
if (options.timeout) {
req.socket.setTimeout(options.timeout);
}
});
const XHeaders$1 = defineProxyMiddleware((req, res, options) => {
if (!options.xfwd) {
return;
}
const encrypted = req.isSpdy || hasEncryptedConnection(req);
const values = {
for: req.connection.remoteAddress || req.socket.remoteAddress,
port: getPort(req),
proto: encrypted ? "https" : "http"
};
for (const header of ["for", "port", "proto"]) {
req.headers["x-forwarded-" + header] = (req.headers["x-forwarded-" + header] || "") + (req.headers["x-forwarded-" + header] ? "," : "") + values[header];
}
req.headers["x-forwarded-host"] = req.headers["x-forwarded-host"] || req.headers.host || "";
});
const stream$1 = defineProxyMiddleware(
(req, res, options, server, head, callback) => {
server.emit("start", req, res, options.target || options.forward);
const agents = nativeAgents;
const http = agents.http;
const https = agents.https;
if (options.forward) {
const forwardReq = (options.forward.protocol === "https:" ? https : http).request(setupOutgoing(options.ssl || {}, options, req, "forward"));
const forwardError = createErrorHandler(forwardReq, options.forward);
req.on("error", forwardError);
forwardReq.on("error", forwardError);
(options.buffer || req).pipe(forwardReq);
if (!options.target) {
res.end();
return;
}
}
const proxyReq = (options.target.protocol === "https:" ? https : http).request(setupOutgoing(options.ssl || {}, options, req));
proxyReq.on("socket", (socket) => {
if (server && !proxyReq.getHeader("expect")) {
server.emit("proxyReq", proxyReq, req, res, options);
}
});
if (options.proxyTimeout) {
proxyReq.setTimeout(options.proxyTimeout, function() {
proxyReq.abort();
});
}
req.on("aborted", function() {
proxyReq.abort();
});
const proxyError = createErrorHandler(proxyReq, options.target);
req.on("error", proxyError);
proxyReq.on("error", proxyError);
function createErrorHandler(proxyReq2, url) {
return function proxyError2(err) {
if (req.socket.destroyed && err.code === "ECONNRESET") {
server.emit("econnreset", err, req, res, url);
return proxyReq2.abort();
}
if (callback) {
callback(err, req, res, url);
} else {
server.emit("error", err, req, res, url);
}
};
}
(options.buffer || req).pipe(proxyReq);
proxyReq.on("response", function(proxyRes) {
if (server) {
server.emit("proxyRes", proxyRes, req, res);
}
if (!res.headersSent && !options.selfHandleResponse) {
for (const pass of webOutgoingMiddleware) {
if (pass(req, res, proxyRes, options)) {
break;
}
}
}
if (res.finished) {
if (server) {
server.emit("end", req, res, proxyRes);
}
} else {
res.on("close", function() {
proxyRes.destroy();
});
proxyRes.on("end", function() {
if (server) {
server.emit("end", req, res, proxyRes);
}
});
if (!options.selfHandleResponse) {
proxyRes.pipe(res);
}
}
});
}
);
const webIncomingMiddleware = [
deleteLength,
timeout,
XHeaders$1,
stream$1
];
const checkMethodAndHeader = defineProxyMiddleware((req, socket) => {
if (req.method !== "GET" || !req.headers.upgrade) {
socket.destroy();
return true;
}
if (req.headers.upgrade.toLowerCase() !== "websocket") {
socket.destroy();
return true;
}
});
const XHeaders = defineProxyMiddleware((req, socket, options) => {
if (!options.xfwd) {
return;
}
const values = {
for: req.connection.remoteAddress || req.socket.remoteAddress,
port: getPort(req),
proto: hasEncryptedConnection(req) ? "wss" : "ws"
};
for (const header of ["for", "port", "proto"]) {
req.headers["x-forwarded-" + header] = (req.headers["x-forwarded-" + header] || "") + (req.headers["x-forwarded-" + header] ? "," : "") + values[header];
}
});
const stream = defineProxyMiddleware(
(req, socket, options, server, head, callback) => {
const createHttpHeader = function(line, headers) {
return Object.keys(headers).reduce(
function(head2, key) {
const value = headers[key];
if (!Array.isArray(value)) {
head2.push(key + ": " + value);
return head2;
}
for (const element of value) {
head2.push(key + ": " + element);
}
return head2;
},
[line]
).join("\r\n") + "\r\n\r\n";
};
setupSocket(socket);
if (head && head.length > 0) {
socket.unshift(head);
}
const proxyReq = (isSSL.test(options.target.protocol) ? https__default : http__default).request(setupOutgoing(options.ssl || {}, options, req));
if (server) {
server.emit("proxyReqWs", proxyReq, req, socket, options, head);
}
proxyReq.on("error", onOutgoingError);
proxyReq.on("response", function(res) {
if (!res.upgrade) {
socket.write(
createHttpHeader(
"HTTP/" + res.httpVersion + " " + res.statusCode + " " + res.statusMessage,
res.headers
)
);
res.pipe(socket);
}
});
proxyReq.on("upgrade", function(proxyRes, proxySocket, proxyHead) {
proxySocket.on("error", onOutgoingError);
proxySocket.on("end", function() {
server.emit("close", proxyRes, proxySocket, proxyHead);
});
socket.on("error", function() {
proxySocket.end();
});
setupSocket(proxySocket);
if (proxyHead && proxyHead.length > 0) {
proxySocket.unshift(proxyHead);
}
socket.write(
createHttpHeader("HTTP/1.1 101 Switching Protocols", proxyRes.headers)
);
proxySocket.pipe(socket).pipe(proxySocket);
server.emit("open", proxySocket);
server.emit("proxySocket", proxySocket);
});
proxyReq.end();
function onOutgoingError(err) {
if (callback) {
callback(err, req, socket);
} else {
server.emit("error", err, req, socket);
}
socket.end();
}
}
);
const websocketIncomingMiddleware = [
checkMethodAndHeader,
XHeaders,
stream
];
class ProxyServer extends node_events.EventEmitter {
_server;
_webPasses = [...webIncomingMiddleware];
_wsPasses = [...websocketIncomingMiddleware];
options;
web;
ws;
/**
* Creates the proxy server with specified options.
* @param options - Config object passed to the proxy
*/
constructor(options = {}) {
super();
this.options = options || {};
this.options.prependPath = options.prependPath !== false;
this.web = _createProxyFn("web", this);
this.ws = _createProxyFn("ws", this);
}
/**
* A function that wraps the object in a webserver, for your convenience
* @param port - Port to listen on
* @param hostname - The hostname to listen on
*/
listen(port, hostname) {
const closure = (req, res) => {
this.web(req, res);
};
this._server = this.options.ssl ? https__default.createServer(this.options.ssl, closure) : http__default.createServer(closure);
if (this.options.ws) {
this._server.on("upgrade", (req, socket, head) => {
this._ws(req, socket, head);
});
}
this._server.listen(port, hostname);
return this;
}
/**
* A function that closes the inner webserver and stops listening on given port
*/
close(callback) {
if (this._server) {
this._server.close((...args) => {
this._server = undefined;
if (callback) {
Reflect.apply(callback, undefined, args);
}
});
}
}
before(type, passName, pass) {
if (type !== "ws" && type !== "web") {
throw new Error("type must be `web` or `ws`");
}
const passes = type === "ws" ? this._wsPasses : this._webPasses;
let i = false;
for (const [idx, v] of passes.entries()) {
if (v.name === passName) {
i = idx;
}
}
if (i === false) {
throw new Error("No such pass");
}
passes.splice(i, 0, pass);
}
after(type, passName, pass) {
if (type !== "ws" && type !== "web") {
throw new Error("type must be `web` or `ws`");
}
const passes = type === "ws" ? this._wsPasses : this._webPasses;
let i = false;
for (const [idx, v] of passes.entries()) {
if (v.name === passName) {
i = idx;
}
}
if (i === false) {
throw new Error("No such pass");
}
passes.splice(i++, 0, pass);
}
}
function createProxyServer(options = {}) {
return new ProxyServer(options);
}
function _createProxyFn(type, server) {
return function(req, res, opts, head) {
const requestOptions = { ...opts, ...server.options };
for (const key of ["target", "forward"]) {
if (typeof requestOptions[key] === "string") {
requestOptions[key] = new URL(requestOptions[key]);
}
}
if (!requestOptions.target && !requestOptions.forward) {
return this.emit(
"error",
new Error("Must provide a proper URL as target")
);
}
let _resolve;
let _reject;
const callbackPromise = new Promise((resolve, reject) => {
_resolve = resolve;
_reject = reject;
});
res.on("close", () => {
_resolve();
});
res.on("error", (error) => {
_reject(error);
});
for (const pass of type === "ws" ? server._wsPasses : server._webPasses) {
const stop = pass(
req,
res,
requestOptions,
server,
head,
(error) => {
_reject(error);
}
);
if (stop) {
_resolve();
break;
}
}
return callbackPromise;
};
}
exports.ProxyServer = ProxyServer;
exports.createProxyServer = createProxyServer;

124
Frontend-Learner/node_modules/httpxy/dist/index.d.cts generated vendored Normal file
View file

@ -0,0 +1,124 @@
import * as stream from 'node:stream';
import http, { IncomingMessage, OutgoingMessage } from 'node:http';
import { EventEmitter } from 'node:events';
interface ProxyTargetDetailed {
host: string;
port: number;
protocol?: string;
hostname?: string;
socketPath?: string;
key?: string;
passphrase?: string;
pfx?: Buffer | string;
cert?: string;
ca?: string;
ciphers?: string;
secureProtocol?: string;
}
type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed;
type ProxyTargetUrl = string | Partial<URL>;
interface ProxyServerOptions {
/** URL string to be parsed with the url module. */
target?: ProxyTarget;
/** URL string to be parsed with the url module. */
forward?: ProxyTargetUrl;
/** Object to be passed to http(s).request. */
agent?: any;
/** Object to be passed to https.createServer(). */
ssl?: any;
/** If you want to proxy websockets. */
ws?: boolean;
/** Adds x- forward headers. */
xfwd?: boolean;
/** Verify SSL certificate. */
secure?: boolean;
/** Explicitly specify if we are proxying to another proxy. */
toProxy?: boolean;
/** Specify whether you want to prepend the target's path to the proxy path. */
prependPath?: boolean;
/** Specify whether you want to ignore the proxy path of the incoming request. */
ignorePath?: boolean;
/** Local interface string to bind for outgoing connections. */
localAddress?: string;
/** Changes the origin of the host header to the target URL. */
changeOrigin?: boolean;
/** specify whether you want to keep letter case of response header key */
preserveHeaderKeyCase?: boolean;
/** Basic authentication i.e. 'user:password' to compute an Authorization header. */
auth?: string;
/** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
hostRewrite?: string;
/** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
autoRewrite?: boolean;
/** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
protocolRewrite?: string;
/** Rewrites domain of set-cookie headers. */
cookieDomainRewrite?: false | string | {
[oldDomain: string]: string;
};
/** Rewrites path of set-cookie headers. Default: false */
cookiePathRewrite?: false | string | {
[oldPath: string]: string;
};
/** Object with extra headers to be added to target requests. */
headers?: {
[header: string]: string;
};
/** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
proxyTimeout?: number;
/** Timeout (in milliseconds) for incoming requests */
timeout?: number;
/** If set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the proxyRes event */
selfHandleResponse?: boolean;
/** Buffer */
buffer?: stream.Stream;
}
type ProxyMiddleware = (req: IncomingMessage, res: OutgoingMessage, opts: ProxyServerOptions & {
target: URL;
forward: URL;
}, server?: ProxyServer, head?: Buffer, callback?: (err: any, req: IncomingMessage, socket: OutgoingMessage, url?: any) => void) => void | true;
declare class ProxyServer extends EventEmitter {
private _server?;
_webPasses: ProxyMiddleware[];
_wsPasses: ProxyMiddleware[];
options: ProxyServerOptions;
web: (req: http.IncomingMessage, res: http.OutgoingMessage, opts?: ProxyServerOptions, head?: any) => Promise<void>;
ws: (req: http.IncomingMessage, socket: http.OutgoingMessage, opts: ProxyServerOptions, head?: any) => Promise<void>;
/**
* Creates the proxy server with specified options.
* @param options - Config object passed to the proxy
*/
constructor(options?: ProxyServerOptions);
/**
* A function that wraps the object in a webserver, for your convenience
* @param port - Port to listen on
* @param hostname - The hostname to listen on
*/
listen(port: number, hostname: string): this;
/**
* A function that closes the inner webserver and stops listening on given port
*/
close(callback: () => void): void;
before(type: "ws" | "web", passName: string, pass: ProxyMiddleware): void;
after(type: "ws" | "web", passName: string, pass: ProxyMiddleware): void;
}
/**
* Creates the proxy server.
*
* Examples:
*
* httpProxy.createProxyServer({ .. }, 8000)
* // => '{ web: [Function], ws: [Function] ... }'
*
* @param {Object} Options Config object passed to the proxy
*
* @return {Object} Proxy Proxy object with handlers for `ws` and `web` requests
*
* @api public
*/
declare function createProxyServer(options?: ProxyServerOptions): ProxyServer;
export { ProxyServer, type ProxyServerOptions, type ProxyTargetDetailed, createProxyServer };

124
Frontend-Learner/node_modules/httpxy/dist/index.d.mts generated vendored Normal file
View file

@ -0,0 +1,124 @@
import * as stream from 'node:stream';
import http, { IncomingMessage, OutgoingMessage } from 'node:http';
import { EventEmitter } from 'node:events';
interface ProxyTargetDetailed {
host: string;
port: number;
protocol?: string;
hostname?: string;
socketPath?: string;
key?: string;
passphrase?: string;
pfx?: Buffer | string;
cert?: string;
ca?: string;
ciphers?: string;
secureProtocol?: string;
}
type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed;
type ProxyTargetUrl = string | Partial<URL>;
interface ProxyServerOptions {
/** URL string to be parsed with the url module. */
target?: ProxyTarget;
/** URL string to be parsed with the url module. */
forward?: ProxyTargetUrl;
/** Object to be passed to http(s).request. */
agent?: any;
/** Object to be passed to https.createServer(). */
ssl?: any;
/** If you want to proxy websockets. */
ws?: boolean;
/** Adds x- forward headers. */
xfwd?: boolean;
/** Verify SSL certificate. */
secure?: boolean;
/** Explicitly specify if we are proxying to another proxy. */
toProxy?: boolean;
/** Specify whether you want to prepend the target's path to the proxy path. */
prependPath?: boolean;
/** Specify whether you want to ignore the proxy path of the incoming request. */
ignorePath?: boolean;
/** Local interface string to bind for outgoing connections. */
localAddress?: string;
/** Changes the origin of the host header to the target URL. */
changeOrigin?: boolean;
/** specify whether you want to keep letter case of response header key */
preserveHeaderKeyCase?: boolean;
/** Basic authentication i.e. 'user:password' to compute an Authorization header. */
auth?: string;
/** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
hostRewrite?: string;
/** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
autoRewrite?: boolean;
/** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
protocolRewrite?: string;
/** Rewrites domain of set-cookie headers. */
cookieDomainRewrite?: false | string | {
[oldDomain: string]: string;
};
/** Rewrites path of set-cookie headers. Default: false */
cookiePathRewrite?: false | string | {
[oldPath: string]: string;
};
/** Object with extra headers to be added to target requests. */
headers?: {
[header: string]: string;
};
/** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
proxyTimeout?: number;
/** Timeout (in milliseconds) for incoming requests */
timeout?: number;
/** If set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the proxyRes event */
selfHandleResponse?: boolean;
/** Buffer */
buffer?: stream.Stream;
}
type ProxyMiddleware = (req: IncomingMessage, res: OutgoingMessage, opts: ProxyServerOptions & {
target: URL;
forward: URL;
}, server?: ProxyServer, head?: Buffer, callback?: (err: any, req: IncomingMessage, socket: OutgoingMessage, url?: any) => void) => void | true;
declare class ProxyServer extends EventEmitter {
private _server?;
_webPasses: ProxyMiddleware[];
_wsPasses: ProxyMiddleware[];
options: ProxyServerOptions;
web: (req: http.IncomingMessage, res: http.OutgoingMessage, opts?: ProxyServerOptions, head?: any) => Promise<void>;
ws: (req: http.IncomingMessage, socket: http.OutgoingMessage, opts: ProxyServerOptions, head?: any) => Promise<void>;
/**
* Creates the proxy server with specified options.
* @param options - Config object passed to the proxy
*/
constructor(options?: ProxyServerOptions);
/**
* A function that wraps the object in a webserver, for your convenience
* @param port - Port to listen on
* @param hostname - The hostname to listen on
*/
listen(port: number, hostname: string): this;
/**
* A function that closes the inner webserver and stops listening on given port
*/
close(callback: () => void): void;
before(type: "ws" | "web", passName: string, pass: ProxyMiddleware): void;
after(type: "ws" | "web", passName: string, pass: ProxyMiddleware): void;
}
/**
* Creates the proxy server.
*
* Examples:
*
* httpProxy.createProxyServer({ .. }, 8000)
* // => '{ web: [Function], ws: [Function] ... }'
*
* @param {Object} Options Config object passed to the proxy
*
* @return {Object} Proxy Proxy object with handlers for `ws` and `web` requests
*
* @api public
*/
declare function createProxyServer(options?: ProxyServerOptions): ProxyServer;
export { ProxyServer, type ProxyServerOptions, type ProxyTargetDetailed, createProxyServer };

124
Frontend-Learner/node_modules/httpxy/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,124 @@
import * as stream from 'node:stream';
import http, { IncomingMessage, OutgoingMessage } from 'node:http';
import { EventEmitter } from 'node:events';
interface ProxyTargetDetailed {
host: string;
port: number;
protocol?: string;
hostname?: string;
socketPath?: string;
key?: string;
passphrase?: string;
pfx?: Buffer | string;
cert?: string;
ca?: string;
ciphers?: string;
secureProtocol?: string;
}
type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed;
type ProxyTargetUrl = string | Partial<URL>;
interface ProxyServerOptions {
/** URL string to be parsed with the url module. */
target?: ProxyTarget;
/** URL string to be parsed with the url module. */
forward?: ProxyTargetUrl;
/** Object to be passed to http(s).request. */
agent?: any;
/** Object to be passed to https.createServer(). */
ssl?: any;
/** If you want to proxy websockets. */
ws?: boolean;
/** Adds x- forward headers. */
xfwd?: boolean;
/** Verify SSL certificate. */
secure?: boolean;
/** Explicitly specify if we are proxying to another proxy. */
toProxy?: boolean;
/** Specify whether you want to prepend the target's path to the proxy path. */
prependPath?: boolean;
/** Specify whether you want to ignore the proxy path of the incoming request. */
ignorePath?: boolean;
/** Local interface string to bind for outgoing connections. */
localAddress?: string;
/** Changes the origin of the host header to the target URL. */
changeOrigin?: boolean;
/** specify whether you want to keep letter case of response header key */
preserveHeaderKeyCase?: boolean;
/** Basic authentication i.e. 'user:password' to compute an Authorization header. */
auth?: string;
/** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
hostRewrite?: string;
/** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
autoRewrite?: boolean;
/** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
protocolRewrite?: string;
/** Rewrites domain of set-cookie headers. */
cookieDomainRewrite?: false | string | {
[oldDomain: string]: string;
};
/** Rewrites path of set-cookie headers. Default: false */
cookiePathRewrite?: false | string | {
[oldPath: string]: string;
};
/** Object with extra headers to be added to target requests. */
headers?: {
[header: string]: string;
};
/** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
proxyTimeout?: number;
/** Timeout (in milliseconds) for incoming requests */
timeout?: number;
/** If set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the proxyRes event */
selfHandleResponse?: boolean;
/** Buffer */
buffer?: stream.Stream;
}
type ProxyMiddleware = (req: IncomingMessage, res: OutgoingMessage, opts: ProxyServerOptions & {
target: URL;
forward: URL;
}, server?: ProxyServer, head?: Buffer, callback?: (err: any, req: IncomingMessage, socket: OutgoingMessage, url?: any) => void) => void | true;
declare class ProxyServer extends EventEmitter {
private _server?;
_webPasses: ProxyMiddleware[];
_wsPasses: ProxyMiddleware[];
options: ProxyServerOptions;
web: (req: http.IncomingMessage, res: http.OutgoingMessage, opts?: ProxyServerOptions, head?: any) => Promise<void>;
ws: (req: http.IncomingMessage, socket: http.OutgoingMessage, opts: ProxyServerOptions, head?: any) => Promise<void>;
/**
* Creates the proxy server with specified options.
* @param options - Config object passed to the proxy
*/
constructor(options?: ProxyServerOptions);
/**
* A function that wraps the object in a webserver, for your convenience
* @param port - Port to listen on
* @param hostname - The hostname to listen on
*/
listen(port: number, hostname: string): this;
/**
* A function that closes the inner webserver and stops listening on given port
*/
close(callback: () => void): void;
before(type: "ws" | "web", passName: string, pass: ProxyMiddleware): void;
after(type: "ws" | "web", passName: string, pass: ProxyMiddleware): void;
}
/**
* Creates the proxy server.
*
* Examples:
*
* httpProxy.createProxyServer({ .. }, 8000)
* // => '{ web: [Function], ws: [Function] ... }'
*
* @param {Object} Options Config object passed to the proxy
*
* @return {Object} Proxy Proxy object with handlers for `ws` and `web` requests
*
* @api public
*/
declare function createProxyServer(options?: ProxyServerOptions): ProxyServer;
export { ProxyServer, type ProxyServerOptions, type ProxyTargetDetailed, createProxyServer };

580
Frontend-Learner/node_modules/httpxy/dist/index.mjs generated vendored Normal file
View file

@ -0,0 +1,580 @@
import http from 'node:http';
import https from 'node:https';
import { EventEmitter } from 'node:events';
const upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
const isSSL = /^https|wss/;
function setupOutgoing(outgoing, options, req, forward) {
outgoing.port = options[forward || "target"].port || (isSSL.test(options[forward || "target"].protocol) ? 443 : 80);
for (const e of [
"host",
"hostname",
"socketPath",
"pfx",
"key",
"passphrase",
"cert",
"ca",
"ciphers",
"secureProtocol"
]) {
outgoing[e] = options[forward || "target"][e];
}
outgoing.method = options.method || req.method;
outgoing.headers = { ...req.headers };
if (options.headers) {
outgoing.headers = { ...outgoing.headers, ...options.headers };
}
if (options.auth) {
outgoing.auth = options.auth;
}
if (options.ca) {
outgoing.ca = options.ca;
}
if (isSSL.test(options[forward || "target"].protocol)) {
outgoing.rejectUnauthorized = options.secure === undefined ? true : options.secure;
}
outgoing.agent = options.agent || false;
outgoing.localAddress = options.localAddress;
if (!outgoing.agent) {
outgoing.headers = outgoing.headers || {};
if (typeof outgoing.headers.connection !== "string" || !upgradeHeader.test(outgoing.headers.connection)) {
outgoing.headers.connection = "close";
}
}
const target = options[forward || "target"];
const targetPath = target && options.prependPath !== false ? target.pathname || target.path || "" : "";
const parsed = new URL(req.url, "http://localhost");
let outgoingPath = options.toProxy ? req.url : parsed.pathname + parsed.search || "";
outgoingPath = options.ignorePath ? "" : outgoingPath;
outgoing.path = joinURL(targetPath, outgoingPath);
if (options.changeOrigin) {
outgoing.headers.host = requiresPort(outgoing.port, options[forward || "target"].protocol) && !hasPort(outgoing.host) ? outgoing.host + ":" + outgoing.port : outgoing.host;
}
return outgoing;
}
function joinURL(base, path) {
if (!base || base === "/") {
return path || "/";
}
if (!path || path === "/") {
return base || "/";
}
const baseHasTrailing = base[base.length - 1] === "/";
const pathHasLeading = path[0] === "/";
if (baseHasTrailing && pathHasLeading) {
return base + path.slice(1);
}
if (!baseHasTrailing && !pathHasLeading) {
return base + "/" + path;
}
return base + path;
}
function setupSocket(socket) {
socket.setTimeout(0);
socket.setNoDelay(true);
socket.setKeepAlive(true, 0);
return socket;
}
function getPort(req) {
const res = req.headers.host ? req.headers.host.match(/:(\d+)/) : "";
if (res) {
return res[1];
}
return hasEncryptedConnection(req) ? "443" : "80";
}
function hasEncryptedConnection(req) {
return Boolean(req.connection.encrypted || req.connection.pair);
}
function rewriteCookieProperty(header, config, property) {
if (Array.isArray(header)) {
return header.map(function(headerElement) {
return rewriteCookieProperty(headerElement, config, property);
});
}
return header.replace(
new RegExp(String.raw`(;\s*` + property + "=)([^;]+)", "i"),
function(match, prefix, previousValue) {
let newValue;
if (previousValue in config) {
newValue = config[previousValue];
} else if ("*" in config) {
newValue = config["*"];
} else {
return match;
}
return newValue ? prefix + newValue : "";
}
);
}
function hasPort(host) {
return !!~host.indexOf(":");
}
function requiresPort(_port, _protocol) {
const protocol = _protocol.split(":")[0];
const port = +_port;
if (!port) return false;
switch (protocol) {
case "http":
case "ws": {
return port !== 80;
}
case "https":
case "wss": {
return port !== 443;
}
case "ftp": {
return port !== 21;
}
case "gopher": {
return port !== 70;
}
case "file": {
return false;
}
}
return port !== 0;
}
function defineProxyMiddleware(m) {
return m;
}
function defineProxyOutgoingMiddleware(m) {
return m;
}
const redirectRegex = /^201|30([1278])$/;
const removeChunked = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
if (req.httpVersion === "1.0") {
delete proxyRes.headers["transfer-encoding"];
}
});
const setConnection = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
if (req.httpVersion === "1.0") {
proxyRes.headers.connection = req.headers.connection || "close";
} else if (req.httpVersion !== "2.0" && !proxyRes.headers.connection) {
proxyRes.headers.connection = req.headers.connection || "keep-alive";
}
});
const setRedirectHostRewrite = defineProxyOutgoingMiddleware(
(req, res, proxyRes, options) => {
if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite) && proxyRes.headers.location && redirectRegex.test(String(proxyRes.statusCode))) {
const target = new URL(options.target);
const u = new URL(proxyRes.headers.location);
if (target.host !== u.host) {
return;
}
if (options.hostRewrite) {
u.host = options.hostRewrite;
} else if (options.autoRewrite) {
u.host = req.headers.host;
}
if (options.protocolRewrite) {
u.protocol = options.protocolRewrite;
}
proxyRes.headers.location = u.toString();
}
}
);
const writeHeaders = defineProxyOutgoingMiddleware(
(req, res, proxyRes, options) => {
let rewriteCookieDomainConfig = options.cookieDomainRewrite;
let rewriteCookiePathConfig = options.cookiePathRewrite;
const preserveHeaderKeyCase = options.preserveHeaderKeyCase;
let rawHeaderKeyMap;
const setHeader = function(key, header) {
if (header === undefined) {
return;
}
if (rewriteCookieDomainConfig && key.toLowerCase() === "set-cookie") {
header = rewriteCookieProperty(
header,
rewriteCookieDomainConfig,
"domain"
);
}
if (rewriteCookiePathConfig && key.toLowerCase() === "set-cookie") {
header = rewriteCookieProperty(header, rewriteCookiePathConfig, "path");
}
res.setHeader(String(key).trim(), header);
};
if (typeof rewriteCookieDomainConfig === "string") {
rewriteCookieDomainConfig = { "*": rewriteCookieDomainConfig };
}
if (typeof rewriteCookiePathConfig === "string") {
rewriteCookiePathConfig = { "*": rewriteCookiePathConfig };
}
if (preserveHeaderKeyCase && proxyRes.rawHeaders !== undefined) {
rawHeaderKeyMap = {};
for (let i = 0; i < proxyRes.rawHeaders.length; i += 2) {
const key = proxyRes.rawHeaders[i];
rawHeaderKeyMap[key.toLowerCase()] = key;
}
}
for (let key of Object.keys(proxyRes.headers)) {
const header = proxyRes.headers[key];
if (preserveHeaderKeyCase && rawHeaderKeyMap) {
key = rawHeaderKeyMap[key] || key;
}
setHeader(key, header);
}
}
);
const writeStatusCode = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
if (proxyRes.statusMessage) {
res.statusCode = proxyRes.statusCode;
res.statusMessage = proxyRes.statusMessage;
} else {
res.statusCode = proxyRes.statusCode;
}
});
const webOutgoingMiddleware = [
removeChunked,
setConnection,
setRedirectHostRewrite,
writeHeaders,
writeStatusCode
];
const nativeAgents = { http: http, https: https };
const deleteLength = defineProxyMiddleware((req) => {
if ((req.method === "DELETE" || req.method === "OPTIONS") && !req.headers["content-length"]) {
req.headers["content-length"] = "0";
delete req.headers["transfer-encoding"];
}
});
const timeout = defineProxyMiddleware((req, res, options) => {
if (options.timeout) {
req.socket.setTimeout(options.timeout);
}
});
const XHeaders$1 = defineProxyMiddleware((req, res, options) => {
if (!options.xfwd) {
return;
}
const encrypted = req.isSpdy || hasEncryptedConnection(req);
const values = {
for: req.connection.remoteAddress || req.socket.remoteAddress,
port: getPort(req),
proto: encrypted ? "https" : "http"
};
for (const header of ["for", "port", "proto"]) {
req.headers["x-forwarded-" + header] = (req.headers["x-forwarded-" + header] || "") + (req.headers["x-forwarded-" + header] ? "," : "") + values[header];
}
req.headers["x-forwarded-host"] = req.headers["x-forwarded-host"] || req.headers.host || "";
});
const stream$1 = defineProxyMiddleware(
(req, res, options, server, head, callback) => {
server.emit("start", req, res, options.target || options.forward);
const agents = nativeAgents;
const http = agents.http;
const https = agents.https;
if (options.forward) {
const forwardReq = (options.forward.protocol === "https:" ? https : http).request(setupOutgoing(options.ssl || {}, options, req, "forward"));
const forwardError = createErrorHandler(forwardReq, options.forward);
req.on("error", forwardError);
forwardReq.on("error", forwardError);
(options.buffer || req).pipe(forwardReq);
if (!options.target) {
res.end();
return;
}
}
const proxyReq = (options.target.protocol === "https:" ? https : http).request(setupOutgoing(options.ssl || {}, options, req));
proxyReq.on("socket", (socket) => {
if (server && !proxyReq.getHeader("expect")) {
server.emit("proxyReq", proxyReq, req, res, options);
}
});
if (options.proxyTimeout) {
proxyReq.setTimeout(options.proxyTimeout, function() {
proxyReq.abort();
});
}
req.on("aborted", function() {
proxyReq.abort();
});
const proxyError = createErrorHandler(proxyReq, options.target);
req.on("error", proxyError);
proxyReq.on("error", proxyError);
function createErrorHandler(proxyReq2, url) {
return function proxyError2(err) {
if (req.socket.destroyed && err.code === "ECONNRESET") {
server.emit("econnreset", err, req, res, url);
return proxyReq2.abort();
}
if (callback) {
callback(err, req, res, url);
} else {
server.emit("error", err, req, res, url);
}
};
}
(options.buffer || req).pipe(proxyReq);
proxyReq.on("response", function(proxyRes) {
if (server) {
server.emit("proxyRes", proxyRes, req, res);
}
if (!res.headersSent && !options.selfHandleResponse) {
for (const pass of webOutgoingMiddleware) {
if (pass(req, res, proxyRes, options)) {
break;
}
}
}
if (res.finished) {
if (server) {
server.emit("end", req, res, proxyRes);
}
} else {
res.on("close", function() {
proxyRes.destroy();
});
proxyRes.on("end", function() {
if (server) {
server.emit("end", req, res, proxyRes);
}
});
if (!options.selfHandleResponse) {
proxyRes.pipe(res);
}
}
});
}
);
const webIncomingMiddleware = [
deleteLength,
timeout,
XHeaders$1,
stream$1
];
const checkMethodAndHeader = defineProxyMiddleware((req, socket) => {
if (req.method !== "GET" || !req.headers.upgrade) {
socket.destroy();
return true;
}
if (req.headers.upgrade.toLowerCase() !== "websocket") {
socket.destroy();
return true;
}
});
const XHeaders = defineProxyMiddleware((req, socket, options) => {
if (!options.xfwd) {
return;
}
const values = {
for: req.connection.remoteAddress || req.socket.remoteAddress,
port: getPort(req),
proto: hasEncryptedConnection(req) ? "wss" : "ws"
};
for (const header of ["for", "port", "proto"]) {
req.headers["x-forwarded-" + header] = (req.headers["x-forwarded-" + header] || "") + (req.headers["x-forwarded-" + header] ? "," : "") + values[header];
}
});
const stream = defineProxyMiddleware(
(req, socket, options, server, head, callback) => {
const createHttpHeader = function(line, headers) {
return Object.keys(headers).reduce(
function(head2, key) {
const value = headers[key];
if (!Array.isArray(value)) {
head2.push(key + ": " + value);
return head2;
}
for (const element of value) {
head2.push(key + ": " + element);
}
return head2;
},
[line]
).join("\r\n") + "\r\n\r\n";
};
setupSocket(socket);
if (head && head.length > 0) {
socket.unshift(head);
}
const proxyReq = (isSSL.test(options.target.protocol) ? https : http).request(setupOutgoing(options.ssl || {}, options, req));
if (server) {
server.emit("proxyReqWs", proxyReq, req, socket, options, head);
}
proxyReq.on("error", onOutgoingError);
proxyReq.on("response", function(res) {
if (!res.upgrade) {
socket.write(
createHttpHeader(
"HTTP/" + res.httpVersion + " " + res.statusCode + " " + res.statusMessage,
res.headers
)
);
res.pipe(socket);
}
});
proxyReq.on("upgrade", function(proxyRes, proxySocket, proxyHead) {
proxySocket.on("error", onOutgoingError);
proxySocket.on("end", function() {
server.emit("close", proxyRes, proxySocket, proxyHead);
});
socket.on("error", function() {
proxySocket.end();
});
setupSocket(proxySocket);
if (proxyHead && proxyHead.length > 0) {
proxySocket.unshift(proxyHead);
}
socket.write(
createHttpHeader("HTTP/1.1 101 Switching Protocols", proxyRes.headers)
);
proxySocket.pipe(socket).pipe(proxySocket);
server.emit("open", proxySocket);
server.emit("proxySocket", proxySocket);
});
proxyReq.end();
function onOutgoingError(err) {
if (callback) {
callback(err, req, socket);
} else {
server.emit("error", err, req, socket);
}
socket.end();
}
}
);
const websocketIncomingMiddleware = [
checkMethodAndHeader,
XHeaders,
stream
];
class ProxyServer extends EventEmitter {
_server;
_webPasses = [...webIncomingMiddleware];
_wsPasses = [...websocketIncomingMiddleware];
options;
web;
ws;
/**
* Creates the proxy server with specified options.
* @param options - Config object passed to the proxy
*/
constructor(options = {}) {
super();
this.options = options || {};
this.options.prependPath = options.prependPath !== false;
this.web = _createProxyFn("web", this);
this.ws = _createProxyFn("ws", this);
}
/**
* A function that wraps the object in a webserver, for your convenience
* @param port - Port to listen on
* @param hostname - The hostname to listen on
*/
listen(port, hostname) {
const closure = (req, res) => {
this.web(req, res);
};
this._server = this.options.ssl ? https.createServer(this.options.ssl, closure) : http.createServer(closure);
if (this.options.ws) {
this._server.on("upgrade", (req, socket, head) => {
this._ws(req, socket, head);
});
}
this._server.listen(port, hostname);
return this;
}
/**
* A function that closes the inner webserver and stops listening on given port
*/
close(callback) {
if (this._server) {
this._server.close((...args) => {
this._server = undefined;
if (callback) {
Reflect.apply(callback, undefined, args);
}
});
}
}
before(type, passName, pass) {
if (type !== "ws" && type !== "web") {
throw new Error("type must be `web` or `ws`");
}
const passes = type === "ws" ? this._wsPasses : this._webPasses;
let i = false;
for (const [idx, v] of passes.entries()) {
if (v.name === passName) {
i = idx;
}
}
if (i === false) {
throw new Error("No such pass");
}
passes.splice(i, 0, pass);
}
after(type, passName, pass) {
if (type !== "ws" && type !== "web") {
throw new Error("type must be `web` or `ws`");
}
const passes = type === "ws" ? this._wsPasses : this._webPasses;
let i = false;
for (const [idx, v] of passes.entries()) {
if (v.name === passName) {
i = idx;
}
}
if (i === false) {
throw new Error("No such pass");
}
passes.splice(i++, 0, pass);
}
}
function createProxyServer(options = {}) {
return new ProxyServer(options);
}
function _createProxyFn(type, server) {
return function(req, res, opts, head) {
const requestOptions = { ...opts, ...server.options };
for (const key of ["target", "forward"]) {
if (typeof requestOptions[key] === "string") {
requestOptions[key] = new URL(requestOptions[key]);
}
}
if (!requestOptions.target && !requestOptions.forward) {
return this.emit(
"error",
new Error("Must provide a proper URL as target")
);
}
let _resolve;
let _reject;
const callbackPromise = new Promise((resolve, reject) => {
_resolve = resolve;
_reject = reject;
});
res.on("close", () => {
_resolve();
});
res.on("error", (error) => {
_reject(error);
});
for (const pass of type === "ws" ? server._wsPasses : server._webPasses) {
const stop = pass(
req,
res,
requestOptions,
server,
head,
(error) => {
_reject(error);
}
);
if (stop) {
_resolve();
break;
}
}
return callbackPromise;
};
}
export { ProxyServer, createProxyServer };

48
Frontend-Learner/node_modules/httpxy/package.json generated vendored Normal file
View file

@ -0,0 +1,48 @@
{
"name": "httpxy",
"version": "0.1.7",
"description": "A full-featured HTTP proxy for Node.js.",
"repository": "unjs/httpxy",
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"dev": "vitest",
"play": "jiti ./playground",
"lint": "eslint --cache . && prettier -c src test",
"lint:fix": "eslint --cache . --fix && prettier -c src test -w",
"prepack": "pnpm run build",
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
"test:types": "tsc --noEmit"
},
"devDependencies": {
"@types/node": "^22.10.10",
"@vitest/coverage-v8": "^3.0.4",
"changelogen": "^0.5.7",
"eslint": "^9.19.0",
"eslint-config-unjs": "^0.4.2",
"jiti": "^2.4.2",
"listhen": "^1.9.0",
"ofetch": "^1.4.1",
"prettier": "^3.4.2",
"typescript": "^5.7.3",
"unbuild": "^3.3.1",
"vitest": "^3.0.4"
},
"packageManager": "pnpm@9.15.4"
}