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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@juleide/proxy

v1.0.0

Published

A simple local server with proxy support, similar to anywhere but with proxy configuration

Readme

Proxy Server

一个简单易用的本地静态服务器,支持代理配置功能,类似于 anywhere,但增加了代理配置功能。

功能特性

  • 🚀 快速启动:一键启动本地静态服务器
  • 🔄 代理支持:灵活的代理配置,支持路径重写
  • 📁 静态文件服务:自动提供指定目录下的静态文件
  • 🌐 自动端口查找:端口被占用时自动寻找可用端口
  • 🖥️ 自动打开浏览器:可选自动打开浏览器访问
  • ⚙️ 灵活配置:支持命令行参数和配置文件两种方式

安装

# 全局安装
npm install -g @julei/proxy

# 或本地安装
npm install @julei/proxy

使用方法

基本使用

# 启动服务器(使用当前目录,默认端口5555)
proxy

# 指定目录和端口
proxy -d ./dist -p 8080

# 自动打开浏览器
proxy --open

命令行参数

| 参数 | 缩写 | 说明 | 默认值 | |------|------|------|--------| | --dir <path> | -d | 要服务的目录 | 当前目录 . | | --port <number> | -p | 监听端口 | 5555 | | --proxy-config <path> | 无 | 代理配置文件路径 | proxy.config.js | | --open | -o | 自动打开浏览器 | false |

代理配置

首次运行时,程序会提示是否生成代理配置文件。配置文件采用 Node.js 模块格式:

// proxy.config.js
module.exports = {
  proxies: [
    {
      prefix: '/api',                           // 代理路径前缀
      target: 'http://192.168.1.116:6010/api', // 目标服务器地址
      rewrite: path => path.replace(/^\/api/, ''), // 路径重写规则
      changeOrigin: true,                       // 是否修改请求头中的host
      ws: true                                  // 是否代理websocket
    },
    {
      prefix: '/upload',
      target: 'http://localhost:3000',
      changeOrigin: true
    }
  ],
  server: {
    port: 5555,        // 服务器端口(可选,优先级低于命令行参数)
    openBrowser: true  // 是否自动打开浏览器(可选)
  }
};

代理配置选项说明

| 选项 | 类型 | 必填 | 说明 | |------|------|------|------| | prefix | string | 是 | 需要代理的路径前缀 | | target | string | 是 | 目标服务器地址(支持 http/https)| | rewrite | function | 否 | 路径重写函数 | | changeOrigin | boolean | 否 | 是否修改请求的 host 头,默认 true | | ws | boolean | 否 | 是否代理 websocket 连接,默认 true |

配置文件与命令行参数的优先级

端口配置的优先级顺序(从高到低):

  1. 命令行参数 -p/--port
  2. 配置文件中的 server.port
  3. 默认值 5555

使用场景示例

场景1:前端开发代理API请求

// proxy.config.js
module.exports = {
  proxies: [
    {
      prefix: '/api',
      target: 'http://api.example.com',
      changeOrigin: true
    }
  ],
  server: {
    port: 3000,
    openBrowser: true
  }
};
# 启动服务器
proxy -d ./public

场景2:多环境代理配置

// proxy.config.js
module.exports = {
  proxies: [
    {
      prefix: '/api/v1',
      target: 'https://api-v1.example.com',
      changeOrigin: true
    },
    {
      prefix: '/api/v2',
      target: 'https://api-v2.example.com',
      changeOrigin: true,
      rewrite: path => path.replace(/^\/api\/v2/, '/v2')
    },
    {
      prefix: '/uploads',
      target: 'http://fileserver.example.com',
      changeOrigin: true
    }
  ]
};

场景3:开发环境快速切换

# 开发环境
proxy -d ./src -p 8080 --open

# 生产构建测试
proxy -d ./dist -p 8080

# 自定义配置文件
proxy --proxy-config ./config/proxy.dev.js

项目结构

proxy-server/
├── bin/
│   └── proxy.js          # 主程序入口
├── package.json          # 项目配置
└── proxy.config.js       # 代理配置文件(自动生成)

技术栈

  • Express: 轻量级 web 框架
  • http-proxy-middleware: 强大的代理中间件
  • commander: 命令行参数解析
  • chalk: 终端彩色输出

注意事项

  1. 端口占用:如果指定端口被占用,程序会自动寻找下一个可用端口
  2. 配置文件:首次运行时会提示生成配置文件,可按需修改
  3. HTTPS 代理:代理 HTTPS 目标时,会自动设置 secure: false
  4. 路径重写:默认会移除前缀路径,可通过 rewrite 函数自定义
  5. 静态文件:未配置代理的路径会作为静态文件处理

常见问题

Q: 如何代理到 HTTPS 服务? A: 直接在 target 中指定 https:// 开头的地址即可,程序会自动处理。

Q: 如何保留原始路径前缀? A: 设置 rewrite: path => path 或省略 rewrite 配置项。

Q: 如何同时代理多个 API 服务? A: 在 proxies 数组中添加多个代理配置对象。

Q: 端口被占用怎么办? A: 程序会自动寻找下一个可用端口,并在控制台显示实际使用的端口。

许可证

MIT License

作者

julei ([email protected])