@buntal/http 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +7 -3
- package/package.json +1 -1
- package/router/index.ts +1 -1
package/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WebSocketHandler } from 'bun'
|
|
1
|
+
import type { ServeFunctionOptions, WebSocketHandler } from 'bun'
|
|
2
2
|
import { Req, Res } from './app'
|
|
3
3
|
import { h, type AtomicHandler } from './handler'
|
|
4
4
|
import type { ALLOWED_METHODS } from './lib/const'
|
|
@@ -13,6 +13,7 @@ type Config = {
|
|
|
13
13
|
match: Bun.MatchedRoute
|
|
14
14
|
handler: any
|
|
15
15
|
}) => Promise<Response | void>
|
|
16
|
+
options?: Partial<ServeFunctionOptions<any, any>>
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
type ExtractRouteParams<Path extends string> =
|
|
@@ -41,10 +42,10 @@ export class Http {
|
|
|
41
42
|
constructor(private config: Config) {}
|
|
42
43
|
|
|
43
44
|
start(cb?: (server: Bun.Server) => void) {
|
|
44
|
-
const res = new Res()
|
|
45
45
|
const middlewares = this.middlewares
|
|
46
46
|
|
|
47
47
|
const server = Bun.serve({
|
|
48
|
+
...this.config.options as any,
|
|
48
49
|
port: this.config.port,
|
|
49
50
|
reusePort: true,
|
|
50
51
|
routes: this.routes,
|
|
@@ -52,6 +53,7 @@ export class Http {
|
|
|
52
53
|
fetch: async (raw: Request, server): Promise<Response | any> => {
|
|
53
54
|
if (this.config.websocket && server.upgrade(raw)) return
|
|
54
55
|
|
|
56
|
+
const res = new Res()
|
|
55
57
|
if (raw.method === 'OPTIONS') {
|
|
56
58
|
return res.send('departed')
|
|
57
59
|
}
|
|
@@ -92,6 +94,7 @@ export class Http {
|
|
|
92
94
|
if (this.errorHandler) {
|
|
93
95
|
return await this.errorHandler(error)
|
|
94
96
|
}
|
|
97
|
+
const res = new Res()
|
|
95
98
|
return res.status(500).json({
|
|
96
99
|
error: error.message,
|
|
97
100
|
details: error.stack
|
|
@@ -182,5 +185,6 @@ export class Http {
|
|
|
182
185
|
}
|
|
183
186
|
|
|
184
187
|
export * from './app'
|
|
185
|
-
export * from './router'
|
|
186
188
|
export * from './handler'
|
|
189
|
+
export * from './router'
|
|
190
|
+
|
package/package.json
CHANGED
package/router/index.ts
CHANGED