@@ -10,9 +10,9 @@ import { extractHostname, serveStaticFile } from '~/server/utils.ts';
1010import type { SSRManifest } from 'astro' ;
1111import type { Server } from 'bun' ;
1212
13- import type { CreateExports , Options } from '~/types.ts' ;
13+ import type { CreateExports , InternalOptions } from '~/types.ts' ;
1414
15- export function createExports ( manifest : SSRManifest , options : Options ) : CreateExports {
15+ export function createExports ( manifest : SSRManifest , options : InternalOptions ) : CreateExports {
1616 return {
1717 handle : handler ( manifest , options ) ,
1818 running : ( ) => _server !== null ,
@@ -26,9 +26,10 @@ export function createExports(manifest: SSRManifest, options: Options): CreateEx
2626}
2727
2828let _server : Server | null = null ;
29- export function start ( manifest : SSRManifest , options : Options ) : void {
29+ export function start ( manifest : SSRManifest , options : InternalOptions ) : void {
3030 const hostname = process . env . HOST ?? extractHostname ( options . host ) ;
3131 const port = process . env . PORT ? Number . parseInt ( process . env . PORT ) : options . port ;
32+ const unix = process . env . UNIX ?? options . unix
3233
3334 if ( cluster . isPrimary && options . cluster ) {
3435 const numCPUs = os . cpus ( ) . length ;
@@ -43,16 +44,27 @@ export function start(manifest: SSRManifest, options: Options): void {
4344 const app = new App ( manifest ) ;
4445 const logger = app . getAdapterLogger ( ) ;
4546
46- _server = Bun . serve ( {
47- development : import . meta. env . DEV ,
48- error : ( error ) =>
49- new Response ( `<pre>${ error } \n${ error . stack } </pre>` , {
50- headers : { 'Content-Type' : 'text/html' } ,
51- } ) ,
52- fetch : handler ( manifest , options ) ,
53- hostname,
54- port,
55- } ) ;
47+ if ( unix ) {
48+ _server = Bun . serve ( {
49+ error : ( error ) =>
50+ new Response ( `<pre>${ error } \n${ error . stack } </pre>` , {
51+ headers : { 'Content-Type' : 'text/html' } ,
52+ } ) ,
53+ fetch : handler ( manifest , options ) ,
54+ unix,
55+ } ) ;
56+ }
57+ else {
58+ _server = Bun . serve ( {
59+ error : ( error ) =>
60+ new Response ( `<pre>${ error } \n${ error . stack } </pre>` , {
61+ headers : { 'Content-Type' : 'text/html' } ,
62+ } ) ,
63+ fetch : handler ( manifest , options ) ,
64+ hostname,
65+ port,
66+ } ) ;
67+ }
5668
5769 function exit ( ) : void {
5870 if ( _server ) _server . stop ( ) ;
@@ -69,7 +81,7 @@ export function start(manifest: SSRManifest, options: Options): void {
6981
7082function handler (
7183 manifest : SSRManifest ,
72- options : Options ,
84+ options : InternalOptions ,
7385) : ( req : Request , server : Server ) => Promise < Response > {
7486 const clientRoot = options . client ?? new URL ( '../client/' , import . meta. url ) . href ;
7587
0 commit comments