std/http/server::serve aligned to std/http/server::serveTLS (#3881)

This commit is contained in:
Kitson Kelly 2020-02-05 01:15:23 +11:00 committed by GitHub
parent 70eccff7f1
commit 145188bcf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -468,10 +468,8 @@ export class Server implements AsyncIterable<ServerRequest> {
}
}
interface ServerConfig {
port: number;
hostname?: string;
}
/** Options for creating an HTTP server. */
export type HTTPOptions = Omit<Deno.ListenOptions, "transport">;
/**
* Start a HTTP server
@ -483,7 +481,7 @@ interface ServerConfig {
* req.respond({ body });
* }
*/
export function serve(addr: string | ServerConfig): Server {
export function serve(addr: string | HTTPOptions): Server {
if (typeof addr === "string") {
const [hostname, port] = addr.split(":");
addr = { hostname, port: Number(port) };
@ -494,7 +492,7 @@ export function serve(addr: string | ServerConfig): Server {
}
export async function listenAndServe(
addr: string | ServerConfig,
addr: string | HTTPOptions,
handler: (req: ServerRequest) => void
): Promise<void> {
const server = serve(addr);