一個簡單的零配置命令行HTTP服務器 - http-server (nodeJs)


http-server 是一個簡單的零配置命令行HTTP服務器, 基於 nodeJs.

如果你不想重復的寫 nodeJs 的 web-server.js, 則可以使用這個.

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

 npm install http-server 

 

Windows 下使用:

在站點目錄下開啟命令行輸入

 http-server

  

訪問: http://localhost:8080 or http://127.0.0.1:8080 

 

使用於package.json

 "scripts": {
     "start": "http-server -a 0.0.0.0 -p 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

-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 打印以上列表並退出
復制代碼

 

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM