日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【Node.js】http-server 实现目录浏览服务

發布時間:2024/9/19 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Node.js】http-server 实现目录浏览服务 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

  • node.js v12.18.2
  • 用 node.js 實現目錄瀏覽服務
  • 前提,已經按照好Node.js
  • http-server 官網:https://www.npmjs.com/package/http-server

下載安裝http-server

shell> npm install http-server -g npm WARN dirservice@1.0.0 No description npm WARN dirservice@1.0.0 No repository field.+ http-server@0.12.3 added 32 packages from 39 contributors and audited 32 packages in 42.284s2 packages are looking for fundingrun `npm fund` for detailsfound 0 vulnerabilities

啟動http-server

命令

http-server [path] [options]

[path]的默認值:先找 ./public ,否則使用 ./ 。

例如:

shell> http-server Starting up http-server, serving ./ Available on:http://192.168.0.165:8080http://127.0.0.1:8080 Hit CTRL-C to stop the server

效果如下:

更多設置

幫助

shell> http-server --help usage: http-server [path] [options]options:-p --port Port to use [8080]-a Address to use [0.0.0.0]-d Show directory listings [true]-i Display autoIndex [true]-g --gzip Serve gzip files when possible [false]-b --brotli Serve brotli files when possible [false]If both brotli and gzip are enabled, brotli takes precedence-e --ext Default file extension if none supplied [none]-s --silent Suppress log messages from output--cors[=headers] Enable CORS via the "Access-Control-Allow-Origin" headerOptionally provide CORS headers list separated by commas-o [path] Open browser window after starting the server.Optionally provide a URL path to open the browser window to.-c Cache time (max-age) in seconds [3600], e.g. -c10 for 10 seconds.To disable caching, use -c-1.-t Connections timeout in seconds [120], e.g. -t60 for 1 minute.To disable timeout, use -t0-U --utc Use UTC time format in log messages.--log-ip Enable logging of the client's IP address-P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com--username Username for basic authentication [none]Can also be specified with the env variable NODE_HTTP_SERVER_USERNAME--password Password for basic authentication [none]Can also be specified with the env variable NODE_HTTP_SERVER_PASSWORD-S --ssl Enable https.-C --cert Path to ssl cert file (default: cert.pem).-K --key Path to ssl key file (default: key.pem).-r --robots Respond to /robots.txt [User-agent: *\nDisallow: /]--no-dotfiles Do not show dotfiles-h --help Print this list and exit.-v --version Print the version and exit.

或者:
參考官網介紹

總結

以上是生活随笔為你收集整理的【Node.js】http-server 实现目录浏览服务的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。