我正在设置一个 Deno 服务器来处理 HTTPS 请求,我使用自签名证书来完成这项工作。为此使用下面的代码:
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 });
}
我将此代码运行为:deno --allow-net --allow-read app.ts
我收到以下错误:
ERROR RS - rustls::session:571 - TLS alert received: Message {
typ: Alert,
version: TLSv1_3,
payload: Alert(
AlertMessagePayload {
level: Fatal,
description: BadCertificate,
},
),
}
error: Uncaught InvalidData: received fatal alert: BadCertificate
► $deno$/errors.ts:57:13
at InvalidData ($deno$/errors.ts:135:5)
at constructError ($deno$/errors.ts:57:13)
at unwrapResponse ($deno$/dispatch_json.ts:41:12)
at sendAsync ($deno$/dispatch_json.ts:96:10)
是否可以在 Deno 中使用自签名证书?出了什么问题以及如何解决?