2020-09-12 08:03:18 -04:00
|
|
|
# File server
|
2020-05-06 18:21:13 -04:00
|
|
|
|
2020-09-12 08:03:18 -04:00
|
|
|
## Concepts
|
|
|
|
|
|
|
|
- Use the Deno standard library
|
|
|
|
[file_server.ts](https://deno.land/std@$STD_VERSION/http/file_server.ts) to
|
2020-09-27 13:49:41 -04:00
|
|
|
run your own file server and access your files from your web browser.
|
2020-09-12 08:03:18 -04:00
|
|
|
- Run [Deno install](../tools/script_installer.md) to install the file server
|
2020-09-27 13:49:41 -04:00
|
|
|
locally.
|
2020-09-12 08:03:18 -04:00
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
Serve a local directory via HTTP. First install the remote script to your local
|
|
|
|
file system. This will install the script to the Deno installation root's bin
|
|
|
|
directory, e.g. `/home/alice/.deno/bin/file_server`.
|
2020-05-06 18:21:13 -04:00
|
|
|
|
2020-05-09 21:09:42 -04:00
|
|
|
```shell
|
2020-07-31 05:12:20 -04:00
|
|
|
deno install --allow-net --allow-read https://deno.land/std@$STD_VERSION/http/file_server.ts
|
2020-05-06 18:21:13 -04:00
|
|
|
```
|
|
|
|
|
2020-09-12 08:03:18 -04:00
|
|
|
You can now run the script with the simplified script name. Run it:
|
2020-05-06 18:21:13 -04:00
|
|
|
|
|
|
|
```shell
|
|
|
|
$ file_server .
|
2020-07-31 05:12:20 -04:00
|
|
|
Downloading https://deno.land/std@$STD_VERSION/http/file_server.ts...
|
2020-05-06 18:21:13 -04:00
|
|
|
[...]
|
2020-09-12 08:03:18 -04:00
|
|
|
HTTP server listening on http://0.0.0.0:4507/
|
2020-05-06 18:21:13 -04:00
|
|
|
```
|
|
|
|
|
2020-09-12 08:03:18 -04:00
|
|
|
Now go to [http://0.0.0.0:4507/](http://0.0.0.0:4507/) in your web browser to
|
|
|
|
see your local directory contents.
|
|
|
|
|
|
|
|
## Help
|
|
|
|
|
|
|
|
Help and a complete list of options are available via:
|
2020-05-06 18:21:13 -04:00
|
|
|
|
|
|
|
```shell
|
2020-09-12 08:03:18 -04:00
|
|
|
file_server --help
|
|
|
|
```
|
|
|
|
|
|
|
|
Example output:
|
|
|
|
|
|
|
|
```
|
|
|
|
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.
|
2020-05-06 18:21:13 -04:00
|
|
|
```
|