35 lines
1.2 KiB
Dart
35 lines
1.2 KiB
Dart
import 'dart:io';
|
|
import 'package:protevus_framework/protevus_framework.dart';
|
|
import 'package:protevus_framework/http.dart';
|
|
import 'package:protevus_shelf/protevus_shelf.dart';
|
|
import 'package:logging/logging.dart';
|
|
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
|
|
import 'package:shelf_static/shelf_static.dart';
|
|
|
|
void main() async {
|
|
Logger.root
|
|
..level = Level.ALL
|
|
..onRecord.listen(prettyLog);
|
|
|
|
var app = Protevus(logger: Logger('protevus_shelf_demo'));
|
|
var http = ProtevusHttp(app);
|
|
|
|
// `shelf` request handler
|
|
var shelfHandler = createStaticHandler('.',
|
|
defaultDocument: 'index.html', listDirectories: true);
|
|
|
|
// Use `embedShelf` to adapt a `shelf` handler for use within Protevus.
|
|
var wrappedHandler = embedShelf(shelfHandler);
|
|
|
|
// A normal Protevus route.
|
|
app.get('/protevus', (req, ResponseContext res) {
|
|
res.write('Hooray for `package:protevus_shelf`!');
|
|
return false; // End execution of handlers, so we don't proxy to dartlang.org when we don't need to.
|
|
});
|
|
|
|
// Pass any other request through to the static file handler
|
|
app.fallback(wrappedHandler);
|
|
|
|
await http.startServer(InternetAddress.loopbackIPv4, 8080);
|
|
print('Running at ${http.uri}');
|
|
}
|