@@ -38,24 +38,33 @@ const app = new Web<{ user?: { id: string } }>();
3838
3939// Middleware
4040app .use (async (ctx , next ) => {
41- console .log (` ${ ctx .req .method } ${ ctx .req .url } ` );
42- await next ();
41+ console .log (` ${ ctx .req .method } ${ ctx .req .url } ` );
42+ await next ();
4343});
4444
4545// Routes
4646app .get (' /' , (ctx ) => ctx .text (' Hello Bun! 🐇' ));
4747
4848app .get (' /users/:id' , async (ctx ) => {
49- const user = await getUser (ctx .params .id );
50- return ctx .json (user);
49+ const user = await getUser (ctx .params .id );
50+ return ctx .json (user);
5151});
5252
53- // Start server
53+ // Start with Bun server
5454Bun .serve ({
55- port: 3000 ,
56- fetch: app .handle
55+ port: 3000 ,
56+ fetch: app .handleBun
5757});
5858
59+ // Start with Deno server
60+ Deno .serve ({ port: 3000 },
61+ (req , info ) => app .handleDeno (req, info)
62+ );
63+
64+ // Start with Node server
65+ import { createServer } from " http" ;
66+ createServer ((req , res ) => app .handleNode (req, res)).listen (3000 );
67+
5968console .log (' Server running at http://localhost:3000' );
6069```
6170
@@ -121,17 +130,17 @@ app.use(async (ctx, next) => {
121130
122131// Path-specific middleware (chainable)
123132app .use (" /admin" , adminAuthMiddleware)
124- .use (" POST" , " /users" , validateUserMiddleware);
133+ .use (" POST" , " /users" , validateUserMiddleware);
125134
126135// Middleware with removal capability
127136const authId = app .addMiddleware (' /admin' , (ctx , next ) => {
128- // Authentication logic
129- await next ();
137+ // Authentication logic
138+ await next ();
130139});
131140
132141const loggingId = app .addMiddleware (async (ctx , next ) => {
133- console .log (` ${ ctx .req .method } ${ ctx .req .url } ` );
134- await next ();
142+ console .log (` ${ ctx .req .method } ${ ctx .req .url } ` );
143+ await next ();
135144});
136145
137146// Remove middleware
0 commit comments