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:
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 {
|
/** 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);
|
||||||
|
|
Loading…
Reference in a new issue