galileo_static 3.0.1 copy "galileo_static: ^3.0.1" to clipboard
galileo_static: ^3.0.1 copied to clipboard

Static server middleware for galileo. Also capable of serving Range responses.

example/main.dart

import 'package:galileo_framework/galileo_framework.dart';
import 'package:galileo_framework/http.dart';
import 'package:galileo_static/galileo_static.dart';
import 'package:file/local.dart';
import 'package:logging/logging.dart';

main(List<String> args) async {
  var app = Galileo();
  var http = GalileoHttp(app);
  var fs = const LocalFileSystem();
  var vDir = CachingVirtualDirectory(
    app,
    fs,
    allowDirectoryListing: true,
    source: args.isEmpty ? fs.currentDirectory : fs.directory(args[0]),
    maxAge: const Duration(days: 24).inSeconds,
  );

  app.mimeTypeResolver
    ..addExtension('', 'text/plain')
    ..addExtension('dart', 'text/dart')
    ..addExtension('lock', 'text/plain')
    ..addExtension('markdown', 'text/plain')
    ..addExtension('md', 'text/plain')
    ..addExtension('yaml', 'text/plain');

  app.logger = Logger('example')
    ..onRecord.listen((rec) {
      print(rec);
      if (rec.error != null) print(rec.error);
      if (rec.stackTrace != null) print(rec.stackTrace);
    });

  app.fallback(vDir.handleRequest);
  app.fallback((req, res) => throw GalileoHttpException.notFound());

  var server = await http.startServer('127.0.0.1', 3000);
  print('Serving from ${vDir.source.path}');
  print('Listening at http://${server.address.address}:${server.port}');
}
0
likes
40
points
20
downloads

Publisher

verified publishergalileodart.com

Weekly Downloads

Static server middleware for galileo. Also capable of serving Range responses.

Repository (GitHub)

License

MIT (license)

Dependencies

convert, crypto, file, galileo_framework, galileo_range_header, http_parser, path

More

Packages that depend on galileo_static