File tree 2 files changed +15
-4
lines changed 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -18,16 +18,23 @@ import 'package:shelf_router/shelf_router.dart';
18
18
import 'package:shelf/shelf.dart';
19
19
import 'package:shelf/shelf_io.dart' as io;
20
20
21
- var app = Router();
21
+ // instantiate a router and configure your routes
22
+ var router = Router();
22
23
23
- app .get('/hello', (Request request) {
24
+ router .get('/hello', (Request request) {
24
25
return Response.ok('hello-world');
25
26
});
26
27
27
- app .get('/user/<user>', (Request request, String user) {
28
+ router .get('/user/<user>', (Request request, String user) {
28
29
return Response.ok('hello $user');
29
30
});
30
31
32
+ // use a Pipeline to configure your middleware,
33
+ // then add the router as the handler
34
+ final app = const Pipeline()
35
+ .addMiddleware(logRequests())
36
+ .addHandler(router);
37
+
31
38
var server = await io.serve(app, 'localhost', 8080);
32
39
```
33
40
Original file line number Diff line number Diff line change @@ -53,7 +53,11 @@ class Service {
53
53
return Response .notFound ('Page not found' );
54
54
});
55
55
56
- return router.call;
56
+ // Set up your Pipeline with any middleware you want to use and set the
57
+ // router as the handler.
58
+ return const Pipeline ()
59
+ .addMiddleware (logRequests ())
60
+ .addHandler (router.call);
57
61
}
58
62
}
59
63
You can’t perform that action at this time.
0 commit comments