资讯

展开

http-server基本使用

作者:快盘下载 人气:

1.什么是http-server

http-server是一个简单的零配置的命令行http服务器(基于nodejs),它足够强大便于生产和使用,用于本地测试和开发。

一般我们打开一个网页都是通过files协议本地打开的方式,当前端项目打包之后想在本地查看发布效果的时候,这时需要在本地开启一个服务,此时http-server开始起作用。

2.基本使用

a.安装node.js

b.安装http-server

npm install -g http-server

进行全局安装,-g表示安装到全局,之后所有文件夹路径下输入http-server都可以使用

c.启动

http-server # 默认是8080端口
# 简写
hs

3.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 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: * Disallow: /’)
-h or --help 打印以上列表并退出

4.关闭 http-server服务

按快捷键CTRL+C

箴言:因为这些东西是非常简单的。不要抱怨自己学不会,那是因为你没有足够用心。



加载全部内容

相关教程
猜你喜欢
用户评论
快盘暂不提供评论功能!