From aab1322be4ced853a8ac18f3400dd229adad38b0 Mon Sep 17 00:00:00 2001 From: Utsob Roy Date: Tue, 19 Sep 2023 12:11:27 +0600 Subject: [PATCH] feat: UNIX socket support for bun preset --- src/runtime/entries/bun.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/runtime/entries/bun.ts b/src/runtime/entries/bun.ts index 0f50d73b8d..c43ebe90cb 100644 --- a/src/runtime/entries/bun.ts +++ b/src/runtime/entries/bun.ts @@ -1,9 +1,21 @@ import "#internal/nitro/virtual/polyfill"; import { nitroApp } from "../app"; + +const options: any = {}; +let listeningOn = ""; + +if (process.env.NITRO_UNIX_SOCKET) { + options.unix = process.env.NITRO_UNIX_SOCKET; + listeningOn = `unix://${process.env.NITRO_UNIX_SOCKET}`; +} else { + options.port = process.env.NITRO_PORT || process.env.PORT || 3000; + listeningOn = `http://localhost:${options.port}` +} + // @ts-expect-error: Bun global const server = Bun.serve({ - port: process.env.NITRO_PORT || process.env.PORT || 3000, + ...options, async fetch(request: Request) { const url = new URL(request.url); @@ -23,4 +35,4 @@ const server = Bun.serve({ }, }); -console.log(`Listening on http://localhost:${server.port}...`); +console.log(`Listening on ${listeningOn}...`);