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

Shelf - Web Server with Dart

Photo by Museums Victoria on Unsplash This article is mostly a gathering of examples from Shelf and its official add-ons. Where I add my own comments that helped me understand the project and building a web server with Shelf, more about that in the end of the blog post. Why Shelf Shelf, is a Web Server Middleware, not a full blown server framework like Django, it is modular, and you add add-ons for the functionalities you need....

November 5, 2021 · 8 min · Filipe Barroso

Deploy a Dart Shelf server to Google Run

Photo by Guille Pozzi on Unsplash Let us learn how to deploy your Dart project to Google Run. I will assume you already have a GCP project running, have gcloud installed, Docker installed, and are familiar with their CLI commands. You will also need a Billing account associated to your GCP Project, and the following GCP services activated in your project: Container Registry API Cloud Run Admin API Cloud Run while has a Free-tier, it is not a Free service, check out the pricing page for more detailed information: https://cloud....

November 13, 2021 · 5 min · Filipe Barroso