http-server
$ http-server 社区开源 中风险http-server(http-party/http-server)可一键将任意本地目录托管为 HTTP/HTTPS 静态服务(http-server ./dist -p 8080 --cors)。支持禁用缓存(-c-1)、SPA/API 代理回退(-P)、基础认证与静默日志(-s),常用于快速本地预览。
brew install http-server http-server 在本地绑定 TCP 端口,用于本地构建预览或浏览器测试期间从磁盘托管静态文件。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持非交互参数(-p、-a、-c-1、--cors、-s),但会作为常驻守护进程阻塞且仅输出非结构化日志,缺少 --json 模式。
- Long-running daemon process; must be backgrounded by the caller
- No
--jsonaccess log format
HTTP 服务本身只读,但未指定 -a 127.0.0.1 时默认监听 0.0.0.0 并开启目录列表,可能向局域网暴露当前目录。
- Defaults to
0.0.0.0unless-a 127.0.0.1is explicitly passed - Serves directory listings unless
-d falseis set
可通过 npx http-server、npm install -g http-server 与 brew install http-server 在 macOS、Linux 与 Windows 运行。
- Zero-install execution via
npx http-server
开箱即用的静态服务器,支持 -c-1、--cors、TLS(-S)与 -P 代理回退。
- Covers static hosting, CORS, TLS, basic auth, and simple proxying
历史悠久的 MIT 社区项目(http-party/http-server)。
- MIT-licensed
http-party/http-serverrepository
README 参数表与 --help 说明直观清晰。
- Documented CLI flags in repository README
安全边界、鉴权与放权指南
无状态工具;可选在启动时通过 --username 与 --password 开启 HTTP 基础认证。
MIT 开源 Node.js CLI,完全免费。
# http-server Agent Rules - Always run `http-server` as a background daemon (it blocks forever until killed). - Bind `-a 127.0.0.1` instead of `0.0.0.0` so local files are not exposed on the LAN. - Pass `-c-1` during development/testing so stale `Cache-Control` headers do not confuse checks.
Agent 高频安全命令配方
只读查询(安全推荐)
http-server ./dist -a 127.0.0.1 -p 8080 -c-1 --cors -s
在 127.0.0.1:8080 启动静态服务器,关闭缓存(-c-1)、启用 CORS 并开启静默日志(-s)。
http-server ./public -a 127.0.0.1 -p 8080 -P http://127.0.0.1:3000
托管 ./public 静态资源,并将未命中的路由转发至本地 API 服务。
核心优势
- + 零配置静态服务(
npx http-server),原生支持-c-1、--cors与-P代理。 - + 通过 npm 与 Homebrew 在各平台均可快速运行。
注意事项与踩坑点
- ! 属于阻塞式服务守护进程:必须以后台方式启动并在结束后清理,否则会卡住同步命令。
- ! 默认监听
0.0.0.0且开启目录索引,建议显式传入-a 127.0.0.1与-d false。