1- import { getGraphQLWSOptions } from '@graphql-hive/gateway-runtime' ;
2- import type { Server , TLSServeOptions , WebSocketServeOptions } from 'bun' ;
1+ import {
2+ DisposableSymbols ,
3+ getGraphQLWSOptions ,
4+ } from '@graphql-hive/gateway-runtime' ;
5+ import type { Server , WebSocketOptions } from 'bun' ;
36import type { Extra } from 'graphql-ws/use/bun' ;
47import { defaultOptions , GatewayRuntime } from '..' ;
58import type { ServerForRuntimeOptions } from './types' ;
@@ -8,36 +11,38 @@ export async function startBunServer<TContext extends Record<string, any>>(
811 gwRuntime : GatewayRuntime < TContext > ,
912 opts : ServerForRuntimeOptions ,
1013) : Promise < void > {
11- const serverOptions : TLSServeOptions & Partial < WebSocketServeOptions > = {
14+ const serverOptions : Bun . Serve . Options < { } > & Partial < WebSocketOptions > = {
1215 fetch : gwRuntime ,
1316 port : opts . port || defaultOptions . port ,
1417 hostname : opts . host || defaultOptions . host ,
1518 reusePort : true ,
1619 idleTimeout : opts . requestTimeout ,
1720 } ;
1821 if ( opts . sslCredentials ) {
22+ const tlsOptions : Bun . TLSOptions = { } ;
1923 if ( opts . sslCredentials . ca_file_name ) {
20- serverOptions . ca = Bun . file ( opts . sslCredentials . ca_file_name ) ;
24+ tlsOptions . ca = Bun . file ( opts . sslCredentials . ca_file_name ) ;
2125 }
2226 if ( opts . sslCredentials . cert_file_name ) {
23- serverOptions . cert = Bun . file ( opts . sslCredentials . cert_file_name ) ;
27+ tlsOptions . cert = Bun . file ( opts . sslCredentials . cert_file_name ) ;
2428 }
2529 if ( opts . sslCredentials . dh_params_file_name ) {
26- serverOptions . dhParamsFile = opts . sslCredentials . dh_params_file_name ;
30+ tlsOptions . dhParamsFile = opts . sslCredentials . dh_params_file_name ;
2731 }
2832 if ( opts . sslCredentials . key_file_name ) {
29- serverOptions . key = Bun . file ( opts . sslCredentials . key_file_name ) ;
33+ tlsOptions . key = Bun . file ( opts . sslCredentials . key_file_name ) ;
3034 }
3135 if ( opts . sslCredentials . passphrase ) {
32- serverOptions . passphrase = opts . sslCredentials . passphrase ;
36+ tlsOptions . passphrase = opts . sslCredentials . passphrase ;
3337 }
3438 if ( opts . sslCredentials . ssl_ciphers ) {
3539 // TODO: Check if there is a correct way to set ciphers
3640 }
3741 if ( opts . sslCredentials . ssl_prefer_low_memory_usage ) {
38- serverOptions . lowMemoryMode =
42+ tlsOptions . lowMemoryMode =
3943 opts . sslCredentials . ssl_prefer_low_memory_usage ;
4044 }
45+ serverOptions . tls = tlsOptions ;
4146 }
4247 if ( ! opts . disableWebsockets ) {
4348 const { makeHandler } = await import ( 'graphql-ws/use/bun' ) ;
@@ -47,7 +52,7 @@ export async function startBunServer<TContext extends Record<string, any>>(
4752 ...( ctx . extra . socket . data || { } ) ,
4853 } ) ) ,
4954 ) ;
50- serverOptions . fetch = function ( request : Request , server : Server ) {
55+ serverOptions . fetch = function ( request : Request , server : Server < { } > ) {
5156 // header to check if websocket
5257 if (
5358 request . headers . has ( 'Sec-WebSocket-Key' ) &&
@@ -65,5 +70,5 @@ export async function startBunServer<TContext extends Record<string, any>>(
6570 }
6671 const server = Bun . serve ( serverOptions ) ;
6772 opts . log . info ( `Listening on ${ server . url } ` ) ;
68- gwRuntime . disposableStack . use ( server ) ;
73+ gwRuntime . disposableStack . defer ( ( ) => server [ DisposableSymbols . dispose ] ( ) ) ;
6974}
0 commit comments