From 9b6913e1a674ceb7f670f917fc355bb8758c6c72 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Mon, 29 May 2023 11:49:51 -0700 Subject: More/better docs for JSX, utils, binary data, streams, hashing, `bun test`, `Bun.serve` (#3005) * WIP * Updates * Document deepEquals * WIP * Update typeS * Update TLS docs for Bun.serve * Update types for tls * Draft binary data page. Add Streams page. * Update test runner docs * Add hashing, flesh out utils * Grammar * Update types * Fix * Add import.meta docs * Tee --- docs/api/tcp.md | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'docs/api/tcp.md') diff --git a/docs/api/tcp.md b/docs/api/tcp.md index cb6d2d783..bcf86d9a8 100644 --- a/docs/api/tcp.md +++ b/docs/api/tcp.md @@ -59,7 +59,7 @@ Bun.listen({ }); ``` -To enable TLS, pass a `tls` object containing `keyFile` and `certFile` properties. +To enable TLS, pass a `tls` object containing `key` and `cert` fields. ```ts Bun.listen({ @@ -69,13 +69,38 @@ Bun.listen({ data(socket, data) {}, }, tls: { - certFile: "cert.pem", - keyFile: "key.pem", + // can be string, BunFile, TypedArray, Buffer, or array thereof + key: Bun.file("./key.pem"), + cert: Bun.file("./cert.pem"), }, }); ``` -The result of `Bun.listen` is a server that conforms to the `TCPSocket` instance. +{% callout %} + +**Note** — Earlier versions of Bun supported passing a file path as `keyFile` and `certFile`; this has been deprecated as of `v0.6.3`. + +{% /callout %} + +The `key` and `cert` fields expect the _contents_ of your TLS key and certificate. This can be a string, `BunFile`, `TypedArray`, or `Buffer`. + +```ts +Bun.listen({ + // ... + tls: { + // BunFile + key: Bun.file("./key.pem"), + // Buffer + key: fs.readFileSync("./key.pem"), + // string + key: fs.readFileSync("./key.pem", "utf8"), + // array of above + key: [Bun.file('./key1.pem'), Bun.file('./key2.pem'] + }, +}); +``` + +The result of `Bun.listen` is a server that conforms to the `TCPSocket` interface. ```ts const server = Bun.listen({ -- cgit v1.2.3