1. What is http-server
http-server is a simple zero-configuration command line http server (based on nodejs), which is powerful enough for production and use, for local testing and development. Generally, we open a webpage files
locally through the protocol. When the front-end project is packaged and want to view the release effect locally, a service needs to be opened locally at this time, and it http-server
starts to work at this time .
Summary: http-server
Run the front-end project locally
2. Basic use
-
installation
npm install -g http-server
-
start up:
http-server # 默认是8080端口 # 简写 hs
After the startup is complete, you can directly access the project on the local port 8080
-
Parameter Description
-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 http://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 打印以上列表并退出