2017-11-18 06:12:59 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
2018-11-13 21:25:17 +00:00
|
|
|
import 'package:angel_framework/http.dart';
|
2017-11-18 06:12:59 +00:00
|
|
|
import 'package:angel_static/angel_static.dart';
|
|
|
|
import 'package:file/local.dart';
|
2018-11-13 21:25:17 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2017-11-18 06:12:59 +00:00
|
|
|
|
2019-01-27 22:14:54 +00:00
|
|
|
main(List<String> args) async {
|
2017-11-18 06:12:59 +00:00
|
|
|
var app = new Angel();
|
2018-07-09 17:38:22 +00:00
|
|
|
var http = new AngelHttp(app);
|
2017-11-18 06:12:59 +00:00
|
|
|
var fs = const LocalFileSystem();
|
2019-01-27 22:14:54 +00:00
|
|
|
var vDir = new CachingVirtualDirectory(
|
|
|
|
app,
|
|
|
|
fs,
|
|
|
|
allowDirectoryListing: true,
|
|
|
|
source: args.isEmpty ? fs.currentDirectory : fs.directory(args[0]),
|
|
|
|
maxAge: const Duration(days: 24).inSeconds,
|
|
|
|
);
|
2018-11-13 21:25:17 +00:00
|
|
|
|
|
|
|
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 = new Logger('example')
|
|
|
|
..onRecord.listen((rec) {
|
|
|
|
print(rec);
|
|
|
|
if (rec.error != null) print(rec.error);
|
|
|
|
if (rec.stackTrace != null) print(rec.stackTrace);
|
|
|
|
});
|
|
|
|
|
2018-08-28 14:58:28 +00:00
|
|
|
app.fallback(vDir.handleRequest);
|
2017-11-18 06:12:59 +00:00
|
|
|
|
2018-07-09 17:38:22 +00:00
|
|
|
var server = await http.startServer('127.0.0.1', 3000);
|
2019-01-27 22:14:54 +00:00
|
|
|
print('Serving from ${vDir.source.path}');
|
2017-11-18 06:12:59 +00:00
|
|
|
print('Listening at http://${server.address.address}:${server.port}');
|
|
|
|
}
|