Skip to content

Commit 525483b

Browse files
committed
refactor: expose serve as standalone util
1 parent fb2e248 commit 525483b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/h3.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ import {
1616
findRoute,
1717
type RouterContext,
1818
} from "rou3";
19-
import { serve, type ServerOptions } from "srvx";
19+
import { serve as srvxServe, type ServerOptions } from "srvx";
2020
import { getPathname, joinURL } from "./utils/internal/path";
2121
import { H3WebEvent } from "./event";
2222
import { kNotFound, prepareResponse } from "./response";
2323
import { createError } from "./error";
2424

25+
/**
26+
* Serve the h3 app, automatically handles current runtime behavior.
27+
*/
28+
export function serve(app: H3, options?: ServerOptions) {
29+
return srvxServe({ fetch: app.fetch, ...options });
30+
}
31+
2532
/**
2633
* Create a new h3 instance.
2734
*/
@@ -63,10 +70,6 @@ class _H3 implements H3 {
6370
};
6471
}
6572

66-
serve(options: ServerOptions) {
67-
return serve({ ...options, fetch: this.fetch });
68-
}
69-
7073
fetch(
7174
_request: Request | URL | string,
7275
options?: RequestInit & { h3?: H3EventContext },

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
export * from "./types";
33

44
// H3
5-
export { createH3 } from "./h3";
5+
export { createH3, serve } from "./h3";
66

77
// Event
88
export { isEvent, mockEvent } from "./utils/event";

0 commit comments

Comments
 (0)