bxo 0.0.5-dev.67 → 0.0.5-dev.69
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/example/index.ts +4 -3
- package/package.json +1 -1
- package/plugins/openapi.ts +1 -1
- package/src/index.ts +11 -13
package/example/index.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import BXO, { z } from "../src";
|
|
2
2
|
import index from "./index.html";
|
|
3
|
-
import openapi from "../plugins/openapi";
|
|
3
|
+
import { openapi } from "../plugins/openapi";
|
|
4
4
|
|
|
5
5
|
async function main() {
|
|
6
6
|
const bxo = new BXO();
|
|
7
7
|
|
|
8
8
|
bxo.default("/", index);
|
|
9
|
+
bxo.default("/*", index);
|
|
9
10
|
|
|
10
|
-
bxo.get("/:id", (ctx) => {
|
|
11
|
+
bxo.get("/api/get/:id", (ctx) => {
|
|
11
12
|
return new Response(ctx.params.id + ctx.query.name, {
|
|
12
13
|
headers: {
|
|
13
14
|
"Content-Type": "text/html"
|
|
@@ -23,7 +24,7 @@ async function main() {
|
|
|
23
24
|
})
|
|
24
25
|
},
|
|
25
26
|
});
|
|
26
|
-
bxo.post("/", (ctx) => {
|
|
27
|
+
bxo.post("/api/post", (ctx) => {
|
|
27
28
|
console.log(ctx.body)
|
|
28
29
|
return new Response("Hello" + ctx.body.name, {
|
|
29
30
|
headers: {
|
package/package.json
CHANGED
package/plugins/openapi.ts
CHANGED
|
@@ -76,7 +76,7 @@ const createOpenApiPaths = (app: BXO, config?: OpenApiPluginConfig): ZodOpenApiP
|
|
|
76
76
|
return paths
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export
|
|
79
|
+
export function openapi(_config?: OpenApiPluginConfig) {
|
|
80
80
|
let config = _config
|
|
81
81
|
!config && (config = { path: "/docs", openapiConfig: new OpenApiConfig(), jsonPath: "/openapi.json" })
|
|
82
82
|
config.path = config.path || "/docs"
|
package/src/index.ts
CHANGED
|
@@ -186,7 +186,7 @@ export default class BXO {
|
|
|
186
186
|
private routes: InternalRoute[] = [];
|
|
187
187
|
private serveOptions: ServeOptions;
|
|
188
188
|
public server?: ReturnType<typeof Bun.serve>;
|
|
189
|
-
|
|
189
|
+
|
|
190
190
|
// Lifecycle hooks
|
|
191
191
|
protected beforeRequestHooks: BeforeRequestHook[] = [];
|
|
192
192
|
protected afterRequestHooks: AfterRequestHook[] = [];
|
|
@@ -208,13 +208,13 @@ export default class BXO {
|
|
|
208
208
|
use(plugin: BXO): this {
|
|
209
209
|
// Merge routes from another BXO instance
|
|
210
210
|
this.routes.push(...plugin.routes);
|
|
211
|
-
|
|
211
|
+
|
|
212
212
|
// Merge lifecycle hooks from plugin
|
|
213
213
|
this.beforeRequestHooks.push(...plugin.beforeRequestHooks);
|
|
214
214
|
this.afterRequestHooks.push(...plugin.afterRequestHooks);
|
|
215
215
|
this.beforeResponseHooks.push(...plugin.beforeResponseHooks);
|
|
216
216
|
this.onErrorHooks.push(...plugin.onErrorHooks);
|
|
217
|
-
|
|
217
|
+
|
|
218
218
|
return this;
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -261,16 +261,14 @@ export default class BXO {
|
|
|
261
261
|
const nativeRoutes: Record<string, Record<string, (req: Request) => Promise<Response> | Response>> = {};
|
|
262
262
|
|
|
263
263
|
for (const r of this.routes) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
264
|
+
switch (r.method) {
|
|
265
|
+
case "DEFAULT":
|
|
266
|
+
nativeRoutes[r.path] = r.handler as any;
|
|
267
|
+
break;
|
|
268
|
+
default:
|
|
269
|
+
nativeRoutes[r.path] ||= {} as Record<string, (req: Request) => Promise<Response> | Response>;
|
|
270
|
+
nativeRoutes[r.path][r.method] = (req: Request) => this.dispatch(r, req);
|
|
271
|
+
break;
|
|
274
272
|
}
|
|
275
273
|
}
|
|
276
274
|
|