-
Notifications
You must be signed in to change notification settings - Fork 16
/
deno_file_server.deno.txt
64 lines (53 loc) · 4.51 KB
/
deno_file_server.deno.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
DENO_FILE_SERVER
ALTERNATIVES ==> #See serve_static
VERSION ==> #Part of Deno
@std/http/file_server.ts
serveFile(REQ, 'PATH'[, OPTS]) NR#Read regular file at 'PATH' and set its contents as RES
->>RES #Contents is streamed directly from file, i.e. does not use memory
#Set:
# - Date: FILE_ATIME [S] (use current time if no atime)
# - Content-Type: MIME [S], based on PATH '.EXT'
# - Content-Length [S]
# - Server: deno [S]
#Handles 404
#Does conditional caching
# - 403 with If-None-Match [C] or If-Modified-Since [C] (but not Cache-Control [C])
# - Last-Modified: FILE_MTIME [S]
# - Etag: {SIZE_HEX}-{MTIME_HASH_BASE64} [S] (see deno_etag doc)
# (if no mtime but Deno deploy)
# - Etag: W/DEPLOYMENT_ID_HASH [S], based on ENVVAR DENO_DEPLOYMENT_ID
#Handles range request:
# - Range[C], Accept-Range [S], Content-Range [S], 206, 416
# - does not support multiple ranges per request, nor If-Range [C]
# - only streams the part of the file being requested, i.e. fast and low-memory
OPTS.fileInfo #FILE_INFO from Deno.stat() (def: automatically done)
OPTS.etagAlgorithm #'ALGO' used for the etag (see deno_etag doc) (def: 'SHA-256')
serveDir(REQ[, OPTS])->> NR#Call serveFile() based on REQ path
#Send 500 response on errors
OPTS.urlRoot #STR (def: none) stripped from REQ path to get 'PATH' to fetch
OPTS.fsRoot #'DIR' (def: '.') used to resolve local 'PATH' to read
OPTS.showIndex #BOOL (def: true). When requesting DIR, serve DIR/index.html if it exists (through 301 redirect)
OPTS.showDirListing #BOOL (def: false). Serve an automatic DIR/index.html if it does not exist
#Shows: link, filename, file size, permission mode
OPTS.showDotfiles #BOOL. If false (def), do not show 'PATH' starting with dot with OPTS.showDirListing true
OPTS.enableCors #BOOL (def: false). Set:
# - Access-Control-Allow-Origin: * [S]
# - Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Range [S]
OPTS.headers #'VAR:VAL'_ARR headers to add to response
#E.g. Cache-Control [S]
OPTS.etagAlgorithm #Like serveFile()
OPTS.quiet #BOOL. If false (def):
# - console.debug() requests: '[DATE] [METHOD] [PATH] STATUS'
# - console.error() exceptions
file_server [DIR] NR#Binary for serveDir()
--host=HOSTNAME #Def: 0.0.0.0
--port|-p=NUM #Def: 8000
--cert|-c=PATH #
--key|-k=PATH #
--no-dir-listing #
--no-dotfiles #
--no-cors #
--header|-H=VAR:VAL #
--verbose|-v #