Skip to main content

@std/http@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
function serveTls
serveTls(
handler: Handler,
options: ServeTlsInit
): Promise<void>
Deprecated

(will be removed after 1.0.0) Use Deno.serve instead.

Serves HTTPS requests with the given handler.

You must specify key or keyFile and cert or certFile options.

You can specify an object with a port and hostname option, which is the address to listen on. The default is port 8443 on hostname "0.0.0.0".

The below example serves with the default port 8443.

import { serveTls } from "@std/http/server";

const cert = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n";
const key = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n";
serveTls((_req) => new Response("Hello, world"), { cert, key });

// Or

const certFile = "/path/to/certFile.crt";
const keyFile = "/path/to/keyFile.key";
serveTls((_req) => new Response("Hello, world"), { certFile, keyFile });

serveTls function prints the message Listening on https://<hostname>:<port>/ on start-up by default. If you like to change this message, you can specify onListen option to override it.

import { serveTls } from "@std/http/server";
const certFile = "/path/to/certFile.crt";
const keyFile = "/path/to/keyFile.key";
serveTls((_req) => new Response("Hello, world"), {
  certFile,
  keyFile,
  onListen({ port, hostname }) {
    console.log(`Server started at https://${hostname}:${port}`);
    // ... more info specific to your server ..
  },
});

You can also specify undefined or null to stop the logging behavior.

import { serveTls } from "@std/http/server";
const certFile = "/path/to/certFile.crt";
const keyFile = "/path/to/keyFile.key";
serveTls((_req) => new Response("Hello, world"), {
  certFile,
  keyFile,
  onListen: undefined,
});

Parameters

The handler for individual HTTPS requests.

The options. See ServeTlsInit documentation for details.

Return Type

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/http

Import symbol

import { serveTls } from "@std/http/server";
or

Import directly with a jsr specifier

import { serveTls } from "jsr:@std/http/server";