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
|
|
|
|
2021-05-01 02:48:36 +00:00
|
|
|
void main(List<String> args) async {
|
2019-05-02 23:29:09 +00:00
|
|
|
var app = Angel();
|
|
|
|
var http = AngelHttp(app);
|
2017-11-18 06:12:59 +00:00
|
|
|
var fs = const LocalFileSystem();
|
2019-05-02 23:29:09 +00:00
|
|
|
var vDir = CachingVirtualDirectory(
|
2019-01-27 22:14:54 +00:00
|
|
|
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');
|
|
|
|
|
2019-05-02 23:29:09 +00:00
|
|
|
app.logger = Logger('example')
|
2018-11-13 21:25:17 +00:00
|
|
|
..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);
|
2019-05-02 23:29:09 +00:00
|
|
|
app.fallback((req, res) => throw AngelHttpException.notFound());
|
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);
|
2021-05-01 03:53:04 +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}');
|
|
|
|
}
|