2018-11-11 17:35:37 +00:00
|
|
|
import 'dart:io';
|
2021-09-14 01:23:03 +00:00
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
|
|
|
import 'package:angel3_framework/http.dart';
|
|
|
|
import 'package:angel3_shelf/angel3_shelf.dart';
|
2019-10-14 15:28:50 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2021-09-25 15:04:25 +00:00
|
|
|
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
|
2018-11-11 17:35:37 +00:00
|
|
|
import 'package:shelf_static/shelf_static.dart';
|
|
|
|
|
2021-06-26 13:13:43 +00:00
|
|
|
void main() async {
|
2019-10-14 15:28:50 +00:00
|
|
|
Logger.root
|
|
|
|
..level = Level.ALL
|
|
|
|
..onRecord.listen(prettyLog);
|
2019-10-14 16:38:30 +00:00
|
|
|
|
2021-09-14 01:23:03 +00:00
|
|
|
var app = Angel(logger: Logger('angel3_shelf_demo'));
|
2019-10-14 15:28:50 +00:00
|
|
|
var http = AngelHttp(app);
|
2018-11-11 17:35:37 +00:00
|
|
|
|
|
|
|
// `shelf` request handler
|
|
|
|
var shelfHandler = createStaticHandler('.',
|
|
|
|
defaultDocument: 'index.html', listDirectories: true);
|
|
|
|
|
|
|
|
// Use `embedShelf` to adapt a `shelf` handler for use within Angel.
|
|
|
|
var wrappedHandler = embedShelf(shelfHandler);
|
|
|
|
|
|
|
|
// A normal Angel route.
|
|
|
|
app.get('/angel', (req, ResponseContext res) {
|
2021-09-14 01:23:03 +00:00
|
|
|
res.write('Hooray for `package:angel3_shelf`!');
|
2018-11-11 17:35:37 +00:00
|
|
|
return false; // End execution of handlers, so we don't proxy to dartlang.org when we don't need to.
|
|
|
|
});
|
|
|
|
|
2019-10-14 15:28:50 +00:00
|
|
|
// Pass any other request through to the static file handler
|
2018-11-11 17:35:37 +00:00
|
|
|
app.fallback(wrappedHandler);
|
|
|
|
|
|
|
|
await http.startServer(InternetAddress.loopbackIPv4, 8080);
|
2019-10-14 15:28:50 +00:00
|
|
|
print('Running at ${http.uri}');
|
2018-11-11 17:35:37 +00:00
|
|
|
}
|