Skip to main content
设置 tls 键来配置 TLS。keycert 都是必需的。key 应该是您的私钥内容;cert 应该是您颁发证书的内容。使用 Bun.file() 来读取内容。
https://mintcdn.com/teemo/2s-4Z6VdGqiCeBNX/icons/typescript.svg?fit=max&auto=format&n=2s-4Z6VdGqiCeBNX&q=85&s=087b260066909db1cd3e9c7292bc34b2server.ts
const server = Bun.serve({
  fetch: request => new Response("欢迎来到 Bun!"),
  tls: {
    cert: Bun.file("cert.pem"),
    key: Bun.file("key.pem"),
  },
});

默认情况下,Bun 信任由 Mozilla 精选的知名根证书颁发机构(CA)列表。要覆盖此列表,请将证书数组作为 ca 传递。
https://mintcdn.com/teemo/2s-4Z6VdGqiCeBNX/icons/typescript.svg?fit=max&auto=format&n=2s-4Z6VdGqiCeBNX&q=85&s=087b260066909db1cd3e9c7292bc34b2server.ts
const server = Bun.serve({
  fetch: request => new Response("欢迎来到 Bun!"),
  tls: {
    cert: Bun.file("cert.pem"),
    key: Bun.file("key.pem"),
    ca: [Bun.file("ca1.pem"), Bun.file("ca2.pem")],
  },
});