介紹一款便捷的http服務工具http-server

web服務

在寫前端頁面時,經常會在瀏覽器運行html頁面,此工具可以快速在本地啟動一個http服務器

http-server可以用來幹啥?

做模擬數據做靜態資源服務器做調試、測試的前端服務器做代理轉發

*本地需要先安裝node環境

1.安裝http-server

2.啟動參數:

-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 (默認3600秒). 禁用緩存使用 -c-1可以自動刷新頁面-U 或 --utc 使用UTC time 格式化log消息-P or --proxy Proxies all requests which can’t be resolved locally to the given url.-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 打印以上列表並退出

3.使用
進入項目根目錄

啟動成功後會打開默認瀏覽器,地址為:http://localhost:8080

4.關閉服務
按快捷鍵CTRL-C,終端顯示^Chttp-server stopped.即可