logo
0
0
WeChat Login
为代理提供一个json提交数据修改的功能

Charonless

Charonless is a simple, lightweight, and easy-to-use library for creating HTTP proxy server in serverless environments. It use basic Fetch API to proxy requests and responses.

How to use?

Charonless provides a single function charon to create a fetch handler. It is a high-level function that takes a default configuration object for handling invalid requests, and a list of testers for proxying requests. The tester is a function that takes a request and returns a proxy configuration object.

Example (serverless env with Bun.js):

import {charon} from 'charonless'; Bun.serve({ fetch(req) { return charon( { host: '192.168.1.1', port: 2000, }, (req) => { if (req.location.host === 'a.example.com') { return { host: '192.168.1.2', port: 2001, } } }, () => { if (req.location.host === 'b.example.com') { return { host: '192.168.1.3', port: 2002, } } } )(req); } })

Proxy Configuration

The proxy behavior is defined through the BackendConfig interface, which allows fine-grained control over request forwarding and response handling. Below are the configuration options available:

type BackendConfig = { host: string; port?: number; ssl?: boolean; followRedirects?: boolean; request?: { path?: (p: string[]) => string[]; headers?: (o: Record<string, string>) => Record<string, string>; query?: (o: Array<[string, string]>) => Array<[string, string]>; json?: (o: any) => Object | undefined; }; response?: { headers?: (o: Record<string, string>) => Record<string, string>; status?: number; body?: (b?: ReadableStream<Uint8Array>) => ReadableStream<Uint8Array> | string; map?: (r?: Response) => Response; }; };

Key Features Explanation:

  1. Core Configuration

host and port define the target backend server location

ssl if true then use https or else use http (default: false)

  1. Request Manipulation

Use request object methods to:

  • Rewrite URL paths
  • Modify headers
  • Adjust query parameters
  1. Response Customization

The response object allows:

  • Header transformations
  • Status code overrides
  • Body modification (supports stream processing)

This structure provides both basic routing and advanced middleware capabilities for proxy operations.

About

charon是一个host在基于Fetch API上的反向代理库。可以通过配置和映射的方式配置代理服务

Language
TypeScript70.4%
Markdown28%
Dockerfile1.6%