Quick Tips - Shelf - notFoundHandler

Simon kindly called to my attention, that we can implement the named parameter notFoundHandler (source) with a Handler in the Router constructor, instead of implementing a router.all() (source). Example import 'package:shelf/shelf.dart'; import 'package:shelf/shelf_io.dart' as shelf_io; import 'package:shelf_router/shelf_router.dart'; void main() async { final service = Service(); final server = await shelf_io.serve(service.handler, 'localhost', 8080); print('Server running on http://${server.address.host}:${server.port}'); } class Service { Handler get handler { final router = Router( // // Instead of using 'router....

November 7, 2021 · 1 min · Filipe Barroso