Bun

指南HTTP

使用 Bun 在 HTTP 伺服器上設定 TLS

設定 tls 鍵以設定 TLS。keycert 都是必要的。key 應為您的私密金鑰內容;cert 應為您發行的憑證內容。使用 Bun.file() 讀取內容。

const server = Bun.serve({
  fetch: request => new Response("Welcome to Bun!"),
  tls: {
    cert: Bun.file("cert.pem"),
    key: Bun.file("key.pem"),
  },
});

預設情況下,Bun 信任 Mozilla 精選的知名根 CA 清單。若要覆寫此清單,請傳遞憑證陣列作為 ca

const server = Bun.serve({
  fetch: request => new Response("Welcome to Bun!"),
  tls: {
    cert: Bun.file("cert.pem"),
    key: Bun.file("key.pem"),
    ca: [Bun.file("ca1.pem"), Bun.file("ca2.pem")],
  },
});