首页 > 解决方案 > 创建 Deno https 服务器

问题描述

我正在寻找在 Deno 中创建 https 服务器的示例。我见过 Deno http 服务器的例子,但没有见过 https。

我尝试在谷歌搜索但没有找到结果

标签: deno

解决方案


serveTLS与 Deno 0.23.0 一起登陆:

示例用法:

import { serveTLS } from "https://deno.land/std/http/server.ts";

const body = new TextEncoder().encode("Hello HTTPS");
const options = {
  hostname: "localhost",
  port: 443,
  certFile: "./path/to/localhost.crt",
  keyFile: "./path/to/localhost.key",
};
// Top-level await supported
for await (const req of serveTLS(options)) {
  req.respond({ body });
}

推荐阅读