diff options
author | Nayeem Rahman <muhammed.9939@gmail.com> | 2020-03-10 16:08:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-10 12:08:58 -0400 |
commit | 6443e4aed16868c17111a56634aa733211430f46 (patch) | |
tree | 8ecbe4d75592fcc78a147b4d69fb61530a0ca2f8 /cli/js/tls.ts | |
parent | fbc4731256a698c07d0d842575d3678d7dc58715 (diff) |
refactor: Cleanup options object parameters (#4296)
Diffstat (limited to 'cli/js/tls.ts')
-rw-r--r-- | cli/js/tls.ts | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/cli/js/tls.ts b/cli/js/tls.ts index 8fff562d2..d7d12ac35 100644 --- a/cli/js/tls.ts +++ b/cli/js/tls.ts @@ -10,14 +10,22 @@ interface ConnectTLSOptions { hostname?: string; certFile?: string; } -const connectTLSDefaults = { hostname: "127.0.0.1", transport: "tcp" }; /** * Establishes a secure connection over TLS (transport layer security). */ -export async function connectTLS(options: ConnectTLSOptions): Promise<Conn> { - options = Object.assign(connectTLSDefaults, options); - const res = await tlsOps.connectTLS(options as tlsOps.ConnectTLSRequest); +export async function connectTLS({ + port, + hostname = "127.0.0.1", + transport = "tcp", + certFile = undefined +}: ConnectTLSOptions): Promise<Conn> { + const res = await tlsOps.connectTLS({ + port, + hostname, + transport, + certFile + }); return new ConnImpl(res.rid, res.remoteAddr!, res.localAddr!); } @@ -49,15 +57,19 @@ export interface ListenTLSOptions { * * Deno.listenTLS({ port: 443, certFile: "./my_server.crt", keyFile: "./my_server.key" }) */ -export function listenTLS(options: ListenTLSOptions): Listener { - const hostname = options.hostname || "0.0.0.0"; - const transport = options.transport || "tcp"; +export function listenTLS({ + port, + certFile, + keyFile, + hostname = "0.0.0.0", + transport = "tcp" +}: ListenTLSOptions): Listener { const res = tlsOps.listenTLS({ + port, + certFile, + keyFile, hostname, - port: options.port, - transport, - certFile: options.certFile, - keyFile: options.keyFile + transport }); return new TLSListenerImpl(res.rid, res.localAddr); } |