New:Socket for Asana Is Now Available.Learn more
Get Started

u32-local-server

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

u32-local-server

Local HTTP file server and proxy

latest
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

u32-local-server

本地 HTTP 文件服务器 + CORS 代理,纯 Node.js 零依赖。

功能特性

  • 📁 本地文件访问 - 通过 HTTP 访问本地文件系统
  • 🌐 CORS 代理 - 绕过跨域限制,代理任意 HTTP/HTTPS 请求
  • 🔐 权限控制 - 白名单/黑名单机制控制文件访问
  • 🎨 可视化配置 - Web 界面管理所有配置
  • 🚀 开机自启 - 支持注册为系统服务
  • 📋 右键菜单 - Windows 集成文件/文件夹右键菜单
  • 📺 目录浏览 - 美观的目录列表页面

快速开始

安装

npm install -g u32-local-server

启动服务器

# 启动服务器(后台运行)
u32-ls start

# 停止服务器
u32-ls stop

# 开发模式(前台运行,监听文件变化)
npm run dev

默认端口 19527,启动后访问:

  • 配置页面:http://localhost:19527/config

使用场景

1. 访问本地文件

直接通过浏览器访问:

  • Linux 用户目录:http://localhost:19527/file/~/
  • Linux 绝对路径:http://localhost:19527/file/home/user/file.txt
  • Windows 盘符:http://localhost:19527/file/C:/Users/user/file.txt

或者使用命令行工具:

# 获取文件/目录 URL
u32-ls url /path/to/file

# 在浏览器中打开
u32-ls open /path/to/file

# 复制 URL 到剪贴板
u32-ls copy-url /path/to/file

2. CORS 代理

用于绕过浏览器的跨域限制:

// 原始 URL(可能有跨域问题)
fetch('https://api.example.com/data')

// 使用代理(无跨域问题)
fetch('http://localhost:19527/proxy/https://api.example.com/data')

代理特性:

  • 删除 accept-encoding 头(返回未压缩内容)
  • 删除 x-frame-options 头(允许 iframe 嵌入)
  • 注入 CORS 头(允许跨域访问)
  • 支持所有 HTTP 方法(GET/POST/PUT/DELETE/PATCH 等)

反向代理(Nginx)

v1.2.0 起页面内全部使用相对链接,可直接挂到 Nginx 子路径下,无需额外配置:

# 子路径转发(挂在大站下):proxy_pass 结尾带 /,剥掉 /ls 前缀
location /ls/ {
    proxy_pass http://127.0.0.1:19527/;
}

# 根路径转发(独立域名/端口)同样支持
location / {
    proxy_pass http://127.0.0.1:19527;
}

访问 https://example.com/ls/ 即可,页面内导航、目录浏览、静态资源、配置页均自动适配代理前缀。

配置

配置文件

位置:~/.u32-local-server/config/main.json

首次启动自动创建,默认配置:

{
  "port": 19527,
  "file": {
    "access": {
      "allow": [],
      "deny": []
    },
    "mime": {
      ".html": "text/html",
      ".js": "text/javascript",
      ".png": "image/png"
      // ... 更多 MIME 类型
    }
  },
  "proxy": {}
}

权限模型

  • allow: 白名单,允许访问的路径前缀
  • deny: 黑名单,拒绝访问的路径前缀
  • 优先级: deny > allow(黑名单优先)
  • allow 为空时,拒绝访问所有文件(白名单模式)
  • 路径支持 ~/ 表示用户主目录

示例:

{
  "file": {
    "access": {
      "allow": ["~/", "/mnt/data"],
      "deny": ["~/敏感文件夹", "/etc"]
    }
  }
}

配置页面

访问 http://localhost:19527/config 可视化管理:

  • 修改端口号
  • 添加/删除访问规则
  • 自定义 MIME 类型

命令参考

命令说明
u32-ls start启动后台服务器
u32-ls stop停止服务器
u32-ls restart重启服务器
u32-ls status查看服务器状态
u32-ls logs [-f]查看服务器日志
u32-ls url <path>获取文件 URL
u32-ls open <path>在浏览器中打开
u32-ls copy-url <path>复制 URL 到剪贴板
u32-ls register注册开机自启 + 右键菜单
u32-ls unregister取消注册
u32-ls version显示版本号
u32-ls --help显示帮助信息

系统集成

Windows

运行 u32-ls register 后:

  • 开机自启: 注册到注册表 Run
  • 文件右键菜单:
    • 「在浏览器中打开」- 直接在浏览器打开文件
    • 「复制 URL」- 复制文件的访问 URL
  • 文件夹右键菜单:
    • 「在浏览器中打开」- 在浏览器浏览文件夹
    • 「复制 URL」- 复制文件夹的访问 URL
  • 文件夹背景右键:
    • 「在浏览器中打开当前目录」- 快速打开当前文件夹

Linux

运行 u32-ls register 后:

  • systemd 服务: 创建用户级服务(需要 sudo)
  • 开机自启: 用户登录时自动启动服务

路由表

路由功能
/proxy/<url>CORS 代理
/config配置管理页面
/config/api配置 REST API
/file/<path>文件访问(Windows 盘符/~/ 支持)
/直接映射到文件系统(Linux)

技术架构

  • 纯 Node.js - 零依赖,无第三方包
  • HTTP 服务器 - 使用原生 http 模块
  • 路径处理 - 自动识别 Windows 盘符和 ~
  • MIME 类型 - 内置 60+ 文件类型支持

开发

# 克隆项目
git clone <repo>
cd u32-local-server

# 开发模式(监听文件变化)
npm run dev

# 手动启动
node src/index.js start

许可证

MIT

Keywords

local-server

FAQs

Package last updated on 22 Aug 2026

Related posts