serve property
({Server Function(ServeHandler handler) $1, Server Function(Object options) $2, Server Function(Object options, ServeHandler handler) $3})
get
serve
Overload accessor: $1, $2, $3
Implementation
({
/// Serves HTTP requests with the given handler.
///
/// The below example serves with the port `8000` on hostname `"127.0.0.1"`.
///
/// ```ts
/// Deno.serve((_req) => new Response("Hello, world"));
/// ```
/// Serves HTTP requests with the given option bag and handler.
///
/// You can specify an object with a port and hostname option, which is the
/// address to listen on. The default is port `8000` on hostname `"127.0.0.1"`.
///
/// You can change the address to listen on using the `hostname` and `port`
/// options. The below example serves on port `3000` and hostname `"0.0.0.0"`.
///
/// ```ts
/// Deno.serve(
/// { port: 3000, hostname: "0.0.0.0" },
/// (_req) => new Response("Hello, world")
/// );
/// ```
///
/// You can stop the server with an {@linkcode AbortSignal}. The abort signal
/// needs to be passed as the `signal` option in the options bag. The server
/// aborts when the abort signal is aborted. To wait for the server to close,
/// await the promise returned from the `Deno.serve` API.
///
/// ```ts
/// const ac = new AbortController();
///
/// const server = Deno.serve(
/// { signal: ac.signal },
/// (_req) => new Response("Hello, world")
/// );
/// server.finished.then(() => console.log("Server closed"));
///
/// console.log("Closing server...");
/// ac.abort();
/// ```
///
/// By default `Deno.serve` prints the message
/// `Listening on http://<hostname>:<port>/` on listening. If you like to
/// change this behavior, you can specify a custom `onListen` callback.
///
/// ```ts
/// Deno.serve({
/// onListen({ port, hostname }) {
/// console.log(`Server started at http://${hostname}:${port}`);
/// // ... more info specific to your server ..
/// },
/// }, (_req) => new Response("Hello, world"));
/// ```
///
/// To enable TLS you must specify the `key` and `cert` options.
///
/// ```ts
/// const cert = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n";
/// const key = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n";
/// Deno.serve({ cert, key }, (_req) => new Response("Hello, world"));
/// ```
/// Serves HTTP requests with the given option bag.
///
/// You can specify an object with a port and hostname option, which is the
/// address to listen on. The default is port `8000` on hostname `"127.0.0.1"`.
///
/// ```ts
/// const ac = new AbortController();
///
/// const server = Deno.serve({
/// port: 3000,
/// hostname: "0.0.0.0",
/// handler: (_req) => new Response("Hello, world"),
/// signal: ac.signal,
/// onListen({ port, hostname }) {
/// console.log(`Server started at http://${hostname}:${port}`);
/// },
/// });
/// server.finished.then(() => console.log("Server closed"));
///
/// console.log("Closing server...");
/// ac.abort();
/// ```
_i4.Server Function(_i4.ServeHandler handler) $1,
/// Serves HTTP requests with the given handler.
///
/// The below example serves with the port `8000` on hostname `"127.0.0.1"`.
///
/// ```ts
/// Deno.serve((_req) => new Response("Hello, world"));
/// ```
/// Serves HTTP requests with the given option bag and handler.
///
/// You can specify an object with a port and hostname option, which is the
/// address to listen on. The default is port `8000` on hostname `"127.0.0.1"`.
///
/// You can change the address to listen on using the `hostname` and `port`
/// options. The below example serves on port `3000` and hostname `"0.0.0.0"`.
///
/// ```ts
/// Deno.serve(
/// { port: 3000, hostname: "0.0.0.0" },
/// (_req) => new Response("Hello, world")
/// );
/// ```
///
/// You can stop the server with an {@linkcode AbortSignal}. The abort signal
/// needs to be passed as the `signal` option in the options bag. The server
/// aborts when the abort signal is aborted. To wait for the server to close,
/// await the promise returned from the `Deno.serve` API.
///
/// ```ts
/// const ac = new AbortController();
///
/// const server = Deno.serve(
/// { signal: ac.signal },
/// (_req) => new Response("Hello, world")
/// );
/// server.finished.then(() => console.log("Server closed"));
///
/// console.log("Closing server...");
/// ac.abort();
/// ```
///
/// By default `Deno.serve` prints the message
/// `Listening on http://<hostname>:<port>/` on listening. If you like to
/// change this behavior, you can specify a custom `onListen` callback.
///
/// ```ts
/// Deno.serve({
/// onListen({ port, hostname }) {
/// console.log(`Server started at http://${hostname}:${port}`);
/// // ... more info specific to your server ..
/// },
/// }, (_req) => new Response("Hello, world"));
/// ```
///
/// To enable TLS you must specify the `key` and `cert` options.
///
/// ```ts
/// const cert = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n";
/// const key = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n";
/// Deno.serve({ cert, key }, (_req) => new Response("Hello, world"));
/// ```
/// Serves HTTP requests with the given option bag.
///
/// You can specify an object with a port and hostname option, which is the
/// address to listen on. The default is port `8000` on hostname `"127.0.0.1"`.
///
/// ```ts
/// const ac = new AbortController();
///
/// const server = Deno.serve({
/// port: 3000,
/// hostname: "0.0.0.0",
/// handler: (_req) => new Response("Hello, world"),
/// signal: ac.signal,
/// onListen({ port, hostname }) {
/// console.log(`Server started at http://${hostname}:${port}`);
/// },
/// });
/// server.finished.then(() => console.log("Server closed"));
///
/// console.log("Closing server...");
/// ac.abort();
/// ```
_i4.Server Function(_i2.Object options) $2,
/// Serves HTTP requests with the given handler.
///
/// The below example serves with the port `8000` on hostname `"127.0.0.1"`.
///
/// ```ts
/// Deno.serve((_req) => new Response("Hello, world"));
/// ```
/// Serves HTTP requests with the given option bag and handler.
///
/// You can specify an object with a port and hostname option, which is the
/// address to listen on. The default is port `8000` on hostname `"127.0.0.1"`.
///
/// You can change the address to listen on using the `hostname` and `port`
/// options. The below example serves on port `3000` and hostname `"0.0.0.0"`.
///
/// ```ts
/// Deno.serve(
/// { port: 3000, hostname: "0.0.0.0" },
/// (_req) => new Response("Hello, world")
/// );
/// ```
///
/// You can stop the server with an {@linkcode AbortSignal}. The abort signal
/// needs to be passed as the `signal` option in the options bag. The server
/// aborts when the abort signal is aborted. To wait for the server to close,
/// await the promise returned from the `Deno.serve` API.
///
/// ```ts
/// const ac = new AbortController();
///
/// const server = Deno.serve(
/// { signal: ac.signal },
/// (_req) => new Response("Hello, world")
/// );
/// server.finished.then(() => console.log("Server closed"));
///
/// console.log("Closing server...");
/// ac.abort();
/// ```
///
/// By default `Deno.serve` prints the message
/// `Listening on http://<hostname>:<port>/` on listening. If you like to
/// change this behavior, you can specify a custom `onListen` callback.
///
/// ```ts
/// Deno.serve({
/// onListen({ port, hostname }) {
/// console.log(`Server started at http://${hostname}:${port}`);
/// // ... more info specific to your server ..
/// },
/// }, (_req) => new Response("Hello, world"));
/// ```
///
/// To enable TLS you must specify the `key` and `cert` options.
///
/// ```ts
/// const cert = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n";
/// const key = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n";
/// Deno.serve({ cert, key }, (_req) => new Response("Hello, world"));
/// ```
/// Serves HTTP requests with the given option bag.
///
/// You can specify an object with a port and hostname option, which is the
/// address to listen on. The default is port `8000` on hostname `"127.0.0.1"`.
///
/// ```ts
/// const ac = new AbortController();
///
/// const server = Deno.serve({
/// port: 3000,
/// hostname: "0.0.0.0",
/// handler: (_req) => new Response("Hello, world"),
/// signal: ac.signal,
/// onListen({ port, hostname }) {
/// console.log(`Server started at http://${hostname}:${port}`);
/// },
/// });
/// server.finished.then(() => console.log("Server closed"));
///
/// console.log("Closing server...");
/// ac.abort();
/// ```
_i4.Server Function(
_i2.Object options,
_i4.ServeHandler handler,
) $3,
}) get serve => (
$1: _serve$1,
$2: _serve$2,
$3: _serve$3,
);