@eslym/sveltekit-adapter-bun 2.1.1 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -193,6 +193,10 @@ export type PreCompressOptions = {
193
193
  | `HTTP_OVERRIDE_ORIGIN` | Force the request origin when it is unable to retrieve from the request | - |
194
194
  | `HTTP_IDLE_TIMEOUT` | The request timeout for the server(in seconds) | `30` |
195
195
  | `HTTP_MAX_BODY` | The maximum body size for the request | `128mib` |
196
+ | `TLS_CERT_FILE` | Path to the TLS certificate file (PEM). Enables HTTPS when set alongside `TLS_KEY_FILE` | - |
197
+ | `TLS_KEY_FILE` | Path to the TLS private key file (PEM). Required with `TLS_CERT_FILE` to enable HTTPS | - |
198
+ | `TLS_CA_FILE` | Optional path to a CA bundle file (PEM) | - |
199
+ | `TLS_PASSPHRASE` | Optional passphrase for an encrypted `TLS_KEY_FILE` | - |
196
200
  | `WS_IDLE_TIMEOUT` | The websocket idle timeout (in seconds) | `120` |
197
201
  | `WS_MAX_PAYLOAD` | The maximum payload size for the websocket | `16mib` |
198
202
  | `WS_NO_PING` | Disable automatic ping response | `false` |
@@ -217,44 +217,42 @@ async function serve_static({ request }) {
217
217
  const headers = new Headers(data.headers.map((h2, i) => [headersMap[i], h2]));
218
218
  const file = data.file;
219
219
  headers.set("content-type", file.type);
220
- if (Bun.semver.satisfies(Bun.version, "< 1.3.13")) {
221
- const range = parse_range(request.headers);
222
- if (range) {
223
- const size = data.headers[2];
224
- if (!range[0]) {
225
- headers.set("content-range", `bytes */${size}`);
226
- headers.set("content-length", "0");
227
- return new Response(null, {
228
- status: 416,
229
- headers
230
- });
231
- }
232
- const [_2, rangeStart, rangeEnd] = range;
233
- let startBytes = 0;
234
- let endBytes = size;
235
- if (rangeStart < 0) {
236
- startBytes = size + rangeStart;
237
- } else {
238
- startBytes = rangeStart;
239
- if (rangeEnd)
240
- endBytes = rangeEnd + 1;
241
- }
242
- if (endBytes <= startBytes || startBytes < 0 || endBytes > size) {
243
- headers.set("content-range", `bytes */${size}`);
244
- headers.set("content-length", "0");
245
- return new Response(null, {
246
- status: 416,
247
- headers
248
- });
249
- }
250
- headers.set("content-range", `bytes ${startBytes}-${endBytes - 1}/${size}`);
251
- headers.set("content-length", `${endBytes - startBytes}`);
252
- headers.set("accept-range", "bytes");
253
- return new Response(file.slice(startBytes, endBytes), {
254
- status: 206,
220
+ const range = parse_range(request.headers);
221
+ if (range) {
222
+ const size = data.headers[2];
223
+ if (!range[0]) {
224
+ headers.set("content-range", `bytes */${size}`);
225
+ headers.set("content-length", "0");
226
+ return new Response(null, {
227
+ status: 416,
228
+ headers
229
+ });
230
+ }
231
+ const [_2, rangeStart, rangeEnd] = range;
232
+ let startBytes = 0;
233
+ let endBytes = size;
234
+ if (rangeStart < 0) {
235
+ startBytes = size + rangeStart;
236
+ } else {
237
+ startBytes = rangeStart;
238
+ if (rangeEnd)
239
+ endBytes = rangeEnd + 1;
240
+ }
241
+ if (endBytes <= startBytes || startBytes < 0 || endBytes > size) {
242
+ headers.set("content-range", `bytes */${size}`);
243
+ headers.set("content-length", "0");
244
+ return new Response(null, {
245
+ status: 416,
255
246
  headers
256
247
  });
257
248
  }
249
+ headers.set("content-range", `bytes ${startBytes}-${endBytes - 1}/${size}`);
250
+ headers.set("content-length", `${endBytes - startBytes}`);
251
+ headers.set("accept-range", "bytes");
252
+ return new Response(file.slice(startBytes, endBytes), {
253
+ status: 206,
254
+ headers
255
+ });
258
256
  }
259
257
  headers.set("cache-control", data.immutable ? immutable_ttl : asset_ttl);
260
258
  if (request.headers.has("if-none-match") && request.headers.get("if-none-match") === data.headers[1]) {
@@ -520,9 +518,30 @@ function websocketOptions() {
520
518
  sendPings: !bool_env("WS_NO_PING")
521
519
  };
522
520
  }
521
+ function tlsOptions() {
522
+ const cert = get_env("TLS_CERT_FILE");
523
+ const key = get_env("TLS_KEY_FILE");
524
+ if (!cert || !key) {
525
+ if (cert || key) {
526
+ console.warn("[adapter-bun] TLS_CERT_FILE and TLS_KEY_FILE must both be set. TLS disabled.");
527
+ }
528
+ return {};
529
+ }
530
+ const ca = get_env("TLS_CA_FILE");
531
+ const passphrase = get_env("TLS_PASSPHRASE");
532
+ return {
533
+ tls: {
534
+ cert: Bun.file(cert),
535
+ key: Bun.file(key),
536
+ ...ca ? { ca: Bun.file(ca) } : {},
537
+ ...passphrase ? { passphrase } : {}
538
+ }
539
+ };
540
+ }
523
541
  function serve() {
524
542
  const server2 = Bun.serve({
525
543
  ...serveOptions(),
544
+ ...tlsOptions(),
526
545
  fetch: create_fetch({
527
546
  overrideOrigin: get_env("HTTP_OVERRIDE_ORIGIN"),
528
547
  hostHeader: get_env("HTTP_HOST_HEADER"),
@@ -545,6 +564,7 @@ if (Bun.main === Bun.fileURLToPath(import.meta.url)) {
545
564
  export {
546
565
  websocketOptions,
547
566
  websocketHandler,
567
+ tlsOptions,
548
568
  serveOptions,
549
569
  serve,
550
570
  create_fetch as createBunFetch
package/package.json CHANGED
@@ -38,5 +38,5 @@
38
38
  "@rollup/plugin-node-resolve": "^15.3.1",
39
39
  "rollup": "^4.55.3"
40
40
  },
41
- "version": "2.1.1"
41
+ "version": "2.1.3"
42
42
  }