http-server 是一個簡單的零配置命令行HTTP服務器, 基于 nodeJs.
如果你不想重復的寫 nodeJs 的 web-server.js, 則可以使用這個.
安裝 (全局安裝加 -g) :
npm install http-server
Windows 下使用:
在站點目錄下開啟命令行輸入
http-server
使用于package.json
"scripts": {
"start": "http-server -a 0.0.0.0 -p 8000",
}
在項目文件目錄下命令行
npm start
20170727113515.png
訪問:
http://192.168.56.1:8000
http://172.16.1.206:8000
http://127.0.0.1:8000
參數:
-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](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 打印以上列表并退出