shelf_gzip 3.0.0 copy "shelf_gzip: ^3.0.0" to clipboard
shelf_gzip: ^3.0.0 copied to clipboard

outdated

Shelf middleware to GZIP responses

shelf_gzip #

Shelf middleware that compresses responses with GZIP

Usage #

import 'dart:io';
import 'dart:async' show runZoned;
import 'package:path/path.dart' show join, dirname;
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_static/shelf_static.dart';
import 'package:shelf_gzip/shelf_gzip.dart';

void main() {
  // Assumes the server lives in bin/ and that `pub build` ran
  var pathToBuild =
      join(dirname(Platform.script.toFilePath()), '..', 'build/web');
  var staticHandler =
      createStaticHandler(pathToBuild, defaultDocument: 'index.html');

  var portEnv = Platform.environment['PORT'];
  var port = portEnv == null ? 9999 : int.parse(portEnv);

  runZoned(() async {
    var handler = const shelf.Pipeline()
        .addMiddleware(gzipMiddleware)
        .addHandler(staticHandler);

    await shelf_io.serve(handler, '0.0.0.0', port);

    print("Serving $pathToBuild on port $port");
  }, onError: (e, stackTrace) => print('Server error: $e $stackTrace'));
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

6
likes
20
pub points
82%
popularity

Publisher

verified publisherjpryan.me

Shelf middleware to GZIP responses

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

shelf

More

Packages that depend on shelf_gzip