@@ -13,9 +13,14 @@ import type {
1313 DefaultAppData ,
1414 BasePrefix ,
1515 SchemaAdapter ,
16+ Transport ,
1617} from "./types" ;
1718import { addRoute , createRouter , findRoute } from "rou3" ;
18- import { callCtxModifierHooks , serializeErrorResponse } from "./internal/utils" ;
19+ import {
20+ callCtxModifierHooks ,
21+ detectTransport ,
22+ serializeErrorResponse ,
23+ } from "./internal/utils" ;
1924import type { OpenAPIV3_1 } from "openapi-types" ;
2025import { buildOpenApiDocs , buildScalarHtml } from "./open-api" ;
2126
@@ -227,17 +232,8 @@ export function createApp<TPrefix extends BasePrefix = "">(
227232 } ,
228233
229234 listen : ( port , cb ) => {
230- if ( typeof Bun !== "undefined" ) {
231- Bun . serve ( { port, fetch : app . build ( ) } ) ;
232- if ( cb ) setTimeout ( cb , 0 ) ;
233- } else if (
234- // @ts -expect-error: Deno types not installed.
235- typeof Deno !== "undefined"
236- ) {
237- // @ts -expect-error: Deno types not installed.
238- Deno . serve ( { port, fetch : app . build ( ) } ) ;
239- if ( cb ) setTimeout ( cb , 0 ) ;
240- }
235+ const transport = options ?. transport ?? detectTransport ( ) ;
236+ transport . listen ( port , app . build ( ) , cb ) ;
241237 return app ;
242238 } ,
243239
@@ -428,6 +424,24 @@ export type CreateAppOptions<TPrefix extends BasePrefix = ""> = {
428424 */
429425 schemaAdapter ?: SchemaAdapter ;
430426
427+ /**
428+ * Tell Zeta how to serve your app over a port. By default, Zeta will detect
429+ * if you're runtime is Bun or Deno, and use the appropriate transport.
430+ *
431+ * If you need to customize the transport, like adding an `idleTimeout` to
432+ * bun, you can do so by passing options into the transport's factory function.
433+ *
434+ * @example
435+ * ```ts
436+ * import { createBunTransport } from "@aklinker1/zeta/transports/bun-transport"
437+ *
438+ * const app = createApp({
439+ * transport: createBunTransport(),
440+ * });
441+ * ```
442+ */
443+ transport ?: Transport ;
444+
431445 /**
432446 * Where the OpenAPI JSON docs is hosted.
433447 * @default "/openapi.json"
0 commit comments