diff options
author | matheus <marchiore.matheus@gmail.com> | 2020-06-03 14:48:03 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-03 13:48:03 -0400 |
commit | 94bf551ead0ab5dc922cb61d13b3141896d5a8ae (patch) | |
tree | d2e9dc2d2115d1b841f2cd83b59bdd02c245fba0 /std/http/file_server.ts | |
parent | 1ebd33092779edc630e8f809f72bcef2656b8185 (diff) |
fix(std/http/file_server): args handling only if invoked directly (#5989)
Diffstat (limited to 'std/http/file_server.ts')
-rwxr-xr-x | std/http/file_server.ts | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/std/http/file_server.ts b/std/http/file_server.ts index 84ca45692..7614c3ab2 100755 --- a/std/http/file_server.ts +++ b/std/http/file_server.ts @@ -34,10 +34,7 @@ interface FileServerArgs { const encoder = new TextEncoder(); const serverArgs = parse(args) as FileServerArgs; - -const CORSEnabled = serverArgs.cors ? true : false; const target = posix.resolve(serverArgs._[0] ?? ""); -const addr = `0.0.0.0:${serverArgs.port ?? serverArgs.p ?? 4507}`; const MEDIA_TYPES: Record<string, string> = { ".md": "text/markdown", @@ -60,23 +57,6 @@ function contentType(path: string): string | undefined { return MEDIA_TYPES[extname(path)]; } -if (serverArgs.h ?? serverArgs.help) { - console.log(`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`); - exit(); -} - function modeToString(isDir: boolean, maybeMode: number | null): string { const modeMap = ["---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"]; @@ -319,6 +299,26 @@ function html(strings: TemplateStringsArray, ...values: unknown[]): string { } function main(): void { + const CORSEnabled = serverArgs.cors ? true : false; + const addr = `0.0.0.0:${serverArgs.port ?? serverArgs.p ?? 4507}`; + + if (serverArgs.h ?? serverArgs.help) { + console.log(`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`); + exit(); + } + listenAndServe( addr, async (req): Promise<void> => { |