-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
622 additions
and
581 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
|
||
[*.{js,ts,mjs,jsx,tsx}] | ||
indent_style = space | ||
insert_final_newline = true | ||
indent_style = space | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"formatter": { | ||
"indentStyle": "space", | ||
"indentWidth": 4 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import type { ServeOptions, Server } from "bun"; | ||
import { createBunWSHandler } from "./createBunWSHandler"; | ||
import { | ||
BunHttpHandlerOptions, | ||
createBunHttpHandler, | ||
BunHttpHandlerOptions, | ||
createBunHttpHandler, | ||
} from "./createBunHttpHandler"; | ||
import type { AnyRouter } from "@trpc/server"; | ||
|
||
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>; | ||
|
||
export function createBunServeHandler<TRouter extends AnyRouter>( | ||
opts: BunHttpHandlerOptions<TRouter>, | ||
serveOptions?: Optional<ServeOptions, "fetch">, | ||
opts: BunHttpHandlerOptions<TRouter>, | ||
serveOptions?: Optional<ServeOptions, "fetch">, | ||
) { | ||
const trpcHandler = createBunHttpHandler({ | ||
...opts, | ||
emitWsUpgrades: true, | ||
}); | ||
const trpcHandler = createBunHttpHandler({ | ||
...opts, | ||
emitWsUpgrades: true, | ||
}); | ||
|
||
return { | ||
...serveOptions, | ||
async fetch(req: Request, server: Server) { | ||
const trpcReponse = trpcHandler(req, server); | ||
return { | ||
...serveOptions, | ||
async fetch(req: Request, server: Server) { | ||
const trpcReponse = trpcHandler(req, server); | ||
|
||
if (trpcReponse) { | ||
return trpcReponse; | ||
} | ||
if (trpcReponse) { | ||
return trpcReponse; | ||
} | ||
|
||
return serveOptions?.fetch?.call(server, req, server); | ||
}, | ||
websocket: createBunWSHandler(opts), | ||
}; | ||
return serveOptions?.fetch?.call(server, req, server); | ||
}, | ||
websocket: createBunWSHandler(opts), | ||
}; | ||
} |
Oops, something went wrong.