介绍一款便捷的http服务工具http-server

web服务

在写前端页面时,经常会在浏览器运行html页面,此工具可以快速在本地启动一个http服务器

http-server可以用来干啥?

做模拟数据做静态资源服务器做调试、测试的前端服务器做代理转发

*本地需要先安装node环境

1.安装http-server

2.启动参数:

-p 端口号 (默认 8080)-a IP 地址 (默认 0.0.0.0)-d 显示目录列表 (默认True)-i 显示 autoIndex (默认True)-e or --ext 如果没有提供默认的文件扩展名(默认html)-s or --silent 禁止日志信息输出--cors 启用 CORS via the Access-Control-Allow-Origin header-o 在开始服务后打开浏览器-c 为 cache-control max-age header 设置Cache time(秒) , e.g. -c10 for 10 seconds (默认3600秒). 禁用缓存使用 -c-1可以自动刷新页面-U 或 --utc 使用UTC time 格式化log消息-P or --proxy Proxies all requests which can’t be resolved locally to the given url.-S or --ssl 启用 https-C or --cert ssl cert 文件路径 (default: cert.pem)-K or --key Path to ssl key file (default: key.pem).-r or --robots Provide a /robots.txt (whose content defaults to ‘User-agent: *\\nDisallow: /’)-h or --help 打印以上列表并退出

3.使用
进入项目根目录

启动成功后会打开默认浏览器,地址为:http://localhost:8080

4.关闭服务
按快捷键CTRL-C,终端显示^Chttp-server stopped.即可