serve method
Starts the server.
Implementation
Future<void> serve(List<Handler> handlers) async {
final router = shelf_router.Router();
for (var handler in handlers) {
router.add(handler.method, handler.path, handler.onRequest);
}
final port =
int.tryParse(Platform.environment['SHOREBIRD_PORT'] ?? '') ?? 3000;
// I'm not sure if the exceptionHandler is working? the
// logRequests might be swallowing the errors instead?
final handler = const shelf.Pipeline()
.addMiddleware(shelf.logRequests())
.addMiddleware(corsHeaders())
.addMiddleware(exceptionHandler())
.addHandler(router);
server = await shelf_io.serve(handler, InternetAddress.anyIPv4, port);
// Enable content compression
server.autoCompress = true;
}