npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@codelook/proxy-server

v0.1.0

Published

HTTP/HTTPS proxy server with Docker deployment and Cloudflare Workers support

Readme

@codelook/proxy-server

一个功能完整的 HTTP/HTTPS 代理服务器,支持 Docker 部署、SSH 一键部署和 Cloudflare Workers。专为解决 API 访问限制和网络隔离问题而设计。

功能特性

  • 🚀 HTTP/HTTPS 代理:完整支持 HTTP 和 HTTPS(CONNECT)代理
  • 🔒 认证机制:Bearer Token 认证保护
  • 🎯 速率限制:防止滥用的请求速率限制
  • 📊 请求日志:详细的请求和响应日志
  • 🐳 Docker 支持:容器化部署,一键启动
  • ☁️ Cloudflare Workers:全球边缘节点部署
  • 🔧 SSH 部署:一键部署到远程服务器
  • 🌐 CORS 支持:跨域请求支持

快速开始

本地运行

# 安装依赖
npm install

# 生成认证令牌
npx proxy-server generate-token

# 启动服务器
npx proxy-server start --auth --token YOUR_TOKEN

# 或使用环境变量
export PROXY_AUTH_TOKEN=YOUR_TOKEN
npx proxy-server start --auth

Docker 运行

# 构建镜像
docker build -t codelook/proxy-server .

# 运行容器
docker run -p 8080:8080 \
  -e PROXY_AUTH_TOKEN=YOUR_TOKEN \
  codelook/proxy-server

# 或使用 docker-compose
cd docker
cp .env.example .env
# 编辑 .env 设置你的令牌
docker-compose up -d

一键部署到服务器

方法1:快速部署(推荐)

# 运行快速部署向导
./scripts/quick-deploy.sh

# 向导会引导你:
# 1. 输入服务器信息
# 2. 自动生成认证令牌
# 3. 配置所有参数
# 4. 一键完成部署

方法2:手动配置部署

# 1. 复制并编辑环境配置
cp docker/.env.example docker/.env
# 编辑 .env 文件,设置你的配置

# 2. 运行部署脚本
./scripts/deploy.sh your-server.com root 22

# 脚本会自动:
# - 读取 .env 配置
# - 构建 Docker 镜像
# - 上传到服务器
# - 安装依赖
# - 启动服务

环境配置说明

# docker/.env 文件示例
PORT=8080                              # 代理服务端口
PROXY_AUTH_TOKEN=pst_your_token_here   # 认证令牌(使用 generate-token 生成)
LOG_LEVEL=info                         # 日志级别
RATE_LIMIT_MAX=100                     # 每分钟最大请求数

使用方法

1. 在 codem 中使用

# 创建环境时配置代理
codem create myenv --proxy http://your-proxy:8080

# 设置现有环境的代理
codem proxy set myenv http://your-proxy:8080

2. 使用 curl 测试

# 方式1:使用 X-Target-URL 头
curl -H "Authorization: Bearer YOUR_TOKEN" \
     -H "X-Target-URL: https://api.anthropic.com" \
     http://localhost:8080/

# 方式2:使用查询参数
curl -H "Authorization: Bearer YOUR_TOKEN" \
     "http://localhost:8080/?target=https://api.anthropic.com"

# 方式3:作为 HTTP 代理
curl -x http://localhost:8080 \
     -H "Proxy-Authorization: Bearer YOUR_TOKEN" \
     https://api.anthropic.com

3. 配置环境变量

# 使用认证的代理
export HTTP_PROXY=http://localhost:8080
export HTTPS_PROXY=http://localhost:8080
export PROXY_AUTH_TOKEN=YOUR_TOKEN

# 然后运行你的应用
claude chat "Hello"

配置选项

CLI 选项

proxy-server start [options]

Options:
  -p, --port <number>        Server port (default: 8080)
  -h, --host <string>        Server host (default: 0.0.0.0)
  --auth                     Enable authentication
  --token <string>          Authentication token
  --rate-limit <number>     Max requests per minute (default: 100)
  --log-level <level>       Log level: debug|info|warn|error (default: info)

环境变量

PORT=8080                    # 服务器端口
PROXY_AUTH_TOKEN=xxx        # 认证令牌
LOG_LEVEL=info              # 日志级别
RATE_LIMIT_MAX=100          # 每分钟最大请求数
RATE_LIMIT_WINDOW=60000     # 速率限制窗口(毫秒)

Cloudflare Workers 部署

支持部署到 Cloudflare Workers 实现全球加速:

# 安装 wrangler
npm install -g wrangler

# 登录 Cloudflare
wrangler login

# 部署
cd cloudflare
wrangler publish

# 查看部署指南
cat cloudflare/deploy.md

Workers 限制

  • 请求大小:100MB
  • 执行时间:10ms(免费)/ 50ms(付费)
  • 不支持 WebSocket
  • 不支持流式响应

与 Codem 集成

快速集成

@codelook/codem v0.3.1+ 支持直接使用带认证的代理服务器:

# 1. 部署代理服务器并获取 token
docker-compose up -d
docker logs proxy-server | grep "Auth token"

# 2. 在 codem 中配置代理
codem create claude-cn \
  --proxy http://your-proxy-server.com:8080 \
  --proxy-auth "pst_your_token_here"

# 3. 使用环境运行 Claude
codem run claude-cn

工作原理

  1. Codem 检测到配置了 --proxy-auth 参数
  2. 自动启动本地代理适配器
  3. 适配器为所有请求添加 Authorization: Bearer <token>
  4. 转发请求到您的代理服务器
  5. Claude 进程结束后自动清理

配置示例

# 更新认证 token
codem proxy set claude-cn --auth "pst_new_token"

# 查看代理配置
codem proxy show claude-cn

# 移除代理配置
codem proxy remove claude-cn

API 接口

健康检查

GET /health

Response:
{
  "status": "ok",
  "uptime": 12345,
  "requests": 100
}

代理请求

GET /
Headers:
  Authorization: Bearer YOUR_TOKEN
  X-Target-URL: https://api.example.com/endpoint

Response: 目标服务器的响应

架构设计

┌─────────────┐     ┌──────────────┐     ┌─────────────┐
│   Client    │────▶│ Proxy Server │────▶│Target Server│
└─────────────┘     └──────────────┘     └─────────────┘
                           │
                    ┌──────┴───────┐
                    │              │
              ┌─────▼─────┐  ┌────▼────┐
              │   Auth    │  │Rate Limit│
              └───────────┘  └──────────┘

安全考虑

  1. 认证保护:使用强随机令牌
  2. 速率限制:防止滥用
  3. 域名过滤:可配置允许/禁止的域名
  4. 日志脱敏:不记录敏感信息
  5. HTTPS 支持:支持加密传输

开发

# 开发模式
npm run dev

# 类型检查
npm run typecheck

# 代码检查
npm run lint

# 运行测试
npm test

# 构建
npm run build

故障排除

1. 端口被占用

# 查找占用端口的进程
lsof -i :8080

# 使用其他端口
proxy-server start --port 3128

2. Docker 构建失败

# 清理 Docker 缓存
docker system prune -a

# 重新构建
docker build --no-cache -t codelook/proxy-server .

3. 认证失败

  • 检查令牌是否正确
  • 确保使用 Bearer 前缀
  • 检查环境变量是否设置

性能优化

  • 使用 Node.js cluster 模式提高并发
  • 启用 HTTP Keep-Alive
  • 配置合适的速率限制
  • 使用 Redis 进行分布式速率限制

贡献

欢迎提交 Issue 和 Pull Request!

许可证

MIT © CodeLook Team