搜索插件、代码仓与 APP 分类

插件详情v4.3.0

dhttpd

用于轻松本地托管目录的静态HTTP文件服务器。

AndroidiOSmacOSWindowsLinux
近 30 天下载
3640
喜欢数
141
Pub 分数
140

安装插件

flutter pub add dhttpd

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

dhttpd 是一个为 Flutter 构建的轻量级静态 HTTP 文件服务器,可轻松实现目录内容的本地托管。它允许开发者从指定目录通过 HTTP 提供文件,非常适合测试网页资源、提供静态站点或在开发过程中本地共享文件。该服务器可在 Android、iOS、macOS、Windows 和 Linux 等多个平台上运行,适用于跨平台工作流程。配置简单,dhttpd 提供了一种无需复杂设置即可预览或共享内容的便捷方式。

适合场景

  • 本地开发预览
  • 提供静态 Web 资产
  • 测试 Web 应用程序
  • 在设备间共享文件
  • 快速原型设计

主要特点

  • 简单设置
  • 跨平台支持
  • 静态文件服务
  • Lightweight
  • 在所有主要平台上运行

适合对象

  • Flutter 开发者
  • 前端测试人员
  • 本地 Web 服务器需要
  • Prototyping
  • 开发环境

使用建议

  • 不适用于生产环境
  • 仅限静态文件
  • 未进行身份验证
  • 需要手动配置以进行高级设置
  • 不适合动态内容

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Pub Package CI package publisher

A simple HTTP server that can serve up any directory, built with Dart. Inspired by python -m SimpleHTTPServer.

Install

Use the dart pub global command to install this into your system.

$ dart pub global activate dhttpd

Use

If you have modified your PATH, you can run this server from any local directory.

$ dhttpd

Otherwise you can use the dart pub global command.

$ dart pub global run dhttpd

Here's an example of creating a web app and then running it with this server:

$ dart create -t web web_app
$ cd web_app
$ dart pub get
$ dart run build_runner build -o build
$ dhttpd --path build/web/  # Serves app at http://localhost:8080
HTTPS

If you want to use HTTPS you will need to pass in the path of the SSL certificate and the SSL key file as well as the password string, if a password is set on the key, for example:

$ dart bin/dhttpd.dart --sslcert=example/server_chain.pem --sslkey=example/server_key.pem --sslkeypassword=dartdart
Server HTTPS started on port 8080

See the Dart documentation of SecurityContext.usePrivateKey for more details.

Configure

$ dhttpd --help
    --headers=<headers>                  HTTP headers to apply to each response. Can be used multiple times. Format: header=value;header2=value
    --host=<host>                        The hostname to listen on.
                                         (defaults to "localhost")
-l, --list-files                         List the files in the directory if no index.html is present.
    --path=<path>                        The path to serve. If not set, the current directory is used.
-p, --port=<port>                        The port to listen on. Provide `0` to use a random port.
                                         (defaults to "8080")
-q, --quiet                              Disable logging.
    --sslcert=<sslcert>                  The SSL certificate to use. Also requires sslkey
    --sslkey=<sslkey>                    The key of the SSL certificate to use. Also requires sslcert
    --sslkeypassword=<sslkeypassword>    The password for the key of the SSL certificate to use.
-h, --help                               Displays the help.
    --version                            Prints the version of dhttpd.

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目