angel3_static 8.1.1 copy "angel3_static: ^8.1.1" to clipboard
angel3_static: ^8.1.1 copied to clipboard

This library provides a virtual directory to serve static files for Angel3 framework.

example/main.dart

import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';
import 'package:angel3_static/angel3_static.dart';
import 'package:file/local.dart';
import 'package:logging/logging.dart';

void main(List<String> args) async {
  var app = Angel();
  var http = AngelHttp(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 AngelHttpException.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}');
}
5
likes
130
pub points
66%
popularity

Publisher

verified publisherdukefirehawk.com

This library provides a virtual directory to serve static files for Angel3 framework.

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

angel3_framework, belatuk_range_header, convert, crypto, file, http_parser, logging, path

More

Packages that depend on angel3_static