Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkassimo committed Nov 4, 2019
1 parent c28bac0 commit 41ce8e7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions std/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,25 @@ export async function listenAndServe(
}
}

/** Options for creating an HTTPS server. */
export type HTTPSOptions = Omit<Deno.ListenTLSOptions, "transport">;

/**
* Create an HTTPS server with given options
* @param options Server configuration
* @return Async iterable server instance for incoming requests
*
* const body = new TextEncoder().encode("Hello HTTPS");
* const options = {
* hostname: "localhost",
* port: 443,
* certFile: "./path/to/localhost.crt",
* keyFile: "./path/to/localhost.key",
* };
* for await (const req of serveTLS(options)) {
* req.respond({ body });
* }
*/
export function serveTLS(options: HTTPSOptions): Server {
const tlsOptions: Deno.ListenTLSOptions = {
...options,
Expand All @@ -412,6 +429,22 @@ export function serveTLS(options: HTTPSOptions): Server {
return new Server(listener);
}

/**
* Create an HTTPS server with given options and request handler
* @param options Server configuration
* @param handler request handler
*
* const body = new TextEncoder().encode("Hello HTTPS");
* const options = {
* hostname: "localhost",
* port: 443,
* certFile: "./path/to/localhost.crt",
* keyFile: "./path/to/localhost.key",
* };
* listenAndServeTLS(options, (req) => {
* req.respond({ body });
* });
*/
export async function listenAndServeTLS(
options: HTTPSOptions,
handler: (req: ServerRequest) => void
Expand Down

0 comments on commit 41ce8e7

Please sign in to comment.