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

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

游戏|数码彩彩2024-04-09 7:44:34467A+A-
介绍一款便捷的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.即可

点击这里复制本文地址 版权声明:本文内容由网友提供,该文观点仅代表作者本人。本站(https://www.angyang.net.cn)仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

昂扬百科 © All Rights Reserved.  渝ICP备2023000803号-3网赚杂谈