mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
std/http/server::serve aligned to std/http/server::serveTLS (#3881)
This commit is contained in:
parent
70eccff7f1
commit
145188bcf7
1 changed files with 4 additions and 6 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue