前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >一个简单的零配置命令行HTTP服务器 - http-server (nodeJs)

一个简单的零配置命令行HTTP服务器 - http-server (nodeJs)

作者头像
游魂
发布2018-06-08 17:00:32
1.2K0
发布2018-06-08 17:00:32
举报
文章被收录于专栏:前端开发

请前提安装Node

http-server 是一个简单的零配置命令行HTTP服务器, 基于 nodeJs.

如果你不想重复的写 nodeJs 的 web-server.js, 则可以使用这个.


安装 (全局安装加 -g) :

代码语言:javascript
复制
npm install http-server

Windows 下使用

在站点目录下开启命令行输入:

代码语言:javascript
复制
http-server
# 可以使用简写hs

开启后访问: http://localhost:8080 or http://127.0.0.1:8080

使用于package.json

代码语言:javascript
复制
 “scripts”: {
     “start”: “http-server -a 0.0.0.0 -p 8000”,
 }

参数

代码语言:javascript
复制
-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.


-P or —proxy Proxies all requests which can’t be resolved locally to the given url. e.g.: -P
[http://someurl.com](http://someurl.com "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 打印以上列表并退出

引用文档: a simple zero-configuration command-line http server


本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-4-19 1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档