1.什么是http-server
http-server是一个简单的零配置的命令行http服务器(基于nodejs),它足够强大便于生产和使用,用于本地测试和开发。一般我们打开一个网页都是通过files协议本地打开的方式,当前端项目打包之后想在本地查看发布效果的时候,这时需要在本地开启一个服务,此时http-server开始起作用。 总结:采用http-server本地运行前端项目
2.命令npm i -g http-server 或者 npx http-server . 注意取消了hs这个指令
3.运行http-server . 或者 npx http-server .
.代表当前路径 -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 (defaults to '3600'). 禁用 caching, 则使用 -c-1. -U 或 --utc 使用UTC time 格式化log消息
-P or --proxy Proxies all requests which can't be resolved locally to the given url. e.g.: -P someurl.com
-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 打印以上列表并退出