1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-10 16:11:13 -05:00

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