Skip to content

في Bun، يتيح لك خيار unix في fetch() إرسال طلبات HTTP عبر مقبس unix domain.

ts
const unix = "/var/run/docker.sock";

const response = await fetch("http://localhost/info", { unix });

const body = await response.json();
console.log(body); // { ... }

خيار unix هو سلسلة تحدد مسار الملف المحلي لمقبس unix domain. ستستخدم دالة fetch() المقبس لإرسال الطلب إلى الخادم بدلاً من استخدام اتصال شبكة TCP. https مدعوم أيضًا باستخدام البروتوكول https:// في عنوان URL بدلاً من http://.

لإرسال طلب POST إلى نقطة نهاية API عبر مقبس unix domain:

ts
const response = await fetch("https://hostname/a/path", {
  unix: "/var/run/path/to/unix.sock",
  method: "POST",
  body: JSON.stringify({ message: "مرحبًا من Bun!" }),
  headers: {
    "Content-Type": "application/json",
  },
});

const body = await response.json();

Bun بواسطة www.bunjs.com.cn تحرير