美文网首页
7.8 文件服务器

7.8 文件服务器

作者: 9e8aeff1c70c | 来源:发表于2021-07-07 09:35 被阅读0次

概念

  • 使用file_server.ts的Deno标准库运行您自己的文件服务器,并从您的Web浏览器访问您的文件。
  • 运行Deno install]在本地安装文件服务器。

例子

通过HTTP提供本地目录。首先将远程脚本安装到本地文件系统。这会将脚本安装到Deno安装根目录的bin目录中,例如:/home/alice/.deno/bin/file_server

deno install --allow-net --allow-read https://deno.land/std@0.95.0/http/file_server.ts

现在,您可以使用简化的脚本名称运行该脚本。运行它:

$ file_server .
Downloading https://deno.land/std@0.95.0/http/file_server.ts...
[...]
HTTP server listening on http://0.0.0.0:4507/

现在转到网页浏览器中的http://0.0.0.0:4507/]查看您的本地目录内容。

帮助

可通过以下方式获得帮助和完整的选项列表:

file_server --help

输出示例:

Deno File Server
    Serves a local directory in HTTP.

  INSTALL:
    deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts

  USAGE:
    file_server [path] [options]

  OPTIONS:
    -h, --help          Prints help information
    -p, --port <PORT>   Set port
    --cors              Enable CORS via the "Access-Control-Allow-Origin" header
    --host     <HOST>   Hostname (default is 0.0.0.0)
    -c, --cert <FILE>   TLS certificate file (enables TLS)
    -k, --key  <FILE>   TLS key file (enables TLS)
    --no-dir-listing    Disable directory listing

    All TLS options are required when one is provided.

相关文章

网友评论

      本文标题:7.8 文件服务器

      本文链接:https://www.haomeiwen.com/subject/lgiurltx.html