Skip to content

Commit

Permalink
feat: UNIX socket support for bun preset
Browse files Browse the repository at this point in the history
  • Loading branch information
uroybd authored Sep 19, 2023
1 parent cb2034c commit aab1322
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/runtime/entries/bun.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -23,4 +35,4 @@ const server = Bun.serve({
},
});

console.log(`Listening on http://localhost:${server.port}...`);
console.log(`Listening on ${listeningOn}...`);

0 comments on commit aab1322

Please sign in to comment.