2021-05-15 13:28:26 +00:00
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
|
|
|
import 'package:angel3_framework/http.dart';
|
|
|
|
import 'package:angel3_static/angel3_static.dart';
|
2017-11-18 06:12:59 +00:00
|
|
|
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 {
|
2024-10-12 10:35:14 +00:00
|
|
|
var app = Protevus();
|
|
|
|
var http = ProtevusHttp(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);
|
2024-10-12 10:35:14 +00:00
|
|
|
app.fallback((req, res) => throw ProtevusHttpException.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-07-10 01:48:47 +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}');
|
|
|
|
}
|