Closed
Description
Please update the shelf_router
documentation to include an example that uses middleware.
I was unaware that I had to create my Router
, set up my routes, and then pass it into a Pipeline
. The only shelf_router
examples I could find only ever show how to set up the Router
and then pass it to the serve
function. It took several days before I finally found a StackOverflow question that happened to show how to properly set up the pipeline.
As someone new to shelf
and shelf_router
, this wasn't immediately obvious.
Something like the following block would have been immensely helpful:
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
void main() async {
// set up your router and routes
final router = Router()..get('/', () => Response.ok('hello world!'));
// set your router as the handler for your pipeline
final app = const Pipeline().addMiddleware(logRequests()).addHandler(router.call);
// pass your pipeline into the serve method
await io.serve(app.call, '0.0.0.0', 3000);
}
Thank you!