6

Node零配置服务器之http-server

 3 years ago
source link: https://www.leixuesong.com/3827
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Node零配置服务器之http-server

WEB前端 Nodejs学习 2020年6月16日

http-server是一个简单的零配置Node环境下命令行HTTP静态服务器。在这之前一般常用的HTTP服务器有ApacheNginx。http-server使用起来非常简单,功能也很强大。http-server可以用于本地调试和开发,也可以用于生产环境。下面雷雪松详细的介绍下Node下http-server的用法。

1、npm全局安装http-server,或者直接使用npx运行。

npm install --g http-server
//或者
npx http-server ...

2、http-server用法

http-server [path] [options]。path默认:./public或者./,public目录优先。

3、http-server 参数
-p :端口号。默认:8080。
-a :IP 地址,默认:0.0.0.0。
-d :显示目录列表 ,默认 ‘True’
-i :显示 autoIndex ,默认 ‘True’
-e or –ext :如果没有提供默认的文件扩展名,默认 ‘html’
-s or –silent :禁止日志信息输出
–cors :启用跨域,设置HTTP header跨域参数Access-Control-Allow-Origin
-o :在开始服务后打开浏览器
-c :默认:3600。设置HTTP header 缓存控制max-age时间 , 例如: -c10 表示 10秒,-1表示禁用, 禁止缓存可以使用 -c-1
-U 或 –utc :使用UTC time 格式化log消息
-P or –proxy :配置本地不能解析的代理地址。http-serve -P https://www.leixuesong.com
-S or –ssl :启用 https。
-C or –cert :SSL cert文件路径 (default: cert.pem)
-K or –key: SSL key文件路径 (default: key.pem).
-r or –robots :提供一个/robots.txt文件 (默认: ‘User-agent: *\nDisallow: /’)
-h or –help :查看帮助.
-v or –version:查看版本信息.

来源:Node零配置服务器之http-server


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK