move 2.x into master

This commit is contained in:
Tobe O 2018-12-10 22:30:48 -05:00
parent db6e5f2039
commit 386141269c
5 changed files with 13 additions and 52 deletions

View file

@ -1,23 +1,20 @@
import 'dart:io'; import 'dart:io';
import 'package:angel/src/pretty_logging.dart';
import 'package:angel/angel.dart'; import 'package:angel/angel.dart';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/angel_framework.dart';
import 'package:angel_hot/angel_hot.dart'; import 'package:angel_hot/angel_hot.dart';
import 'package:logging/logging.dart'; import 'package:lumberjack/lumberjack.dart';
import 'package:lumberjack/io.dart';
main() async { main() async {
// Watch the config/ and web/ directories for changes, and hot-reload the server. // Watch the config/ and web/ directories for changes, and hot-reload the server.
var hot = new HotReloader(() async { var hot = HotReloader(() async {
var app = new Angel(); var app = Angel();
await app.configure(configureServer); await app.configure(configureServer);
hierarchicalLoggingEnabled = true; app.logger = Logger('angel')..pipe(AnsiLogPrinter.toStdout());
app.logger = new Logger('angel'); app.shutdownHooks.add((_) => app.logger.close());
var sub = app.logger.onRecord.listen(prettyLog);
app.shutdownHooks.add((_) => sub.cancel());
return app;
}, [ }, [
new Directory('config'), Directory('config'),
new Directory('lib'), Directory('lib'),
]); ]);
var server = await hot.startServer('127.0.0.1', 3000); var server = await hot.startServer('127.0.0.1', 3000);

View file

@ -1,4 +1,4 @@
import 'package:angel/angel.dart'; import 'package:angel/angel.dart';
import 'package:angel_production/angel_production.dart'; import 'package:angel_production/angel_production.dart';
main(List<String> args) => new Runner('angel', configureServer).run(args); main(List<String> args) => Runner('angel', configureServer).run(args);

View file

@ -1,35 +0,0 @@
import 'package:angel_http_exception/angel_http_exception.dart';
import 'package:logging/logging.dart';
import 'package:io/ansi.dart';
/// Prints the contents of a [LogRecord] with pretty colors.
void prettyLog(LogRecord record) {
var code = chooseLogColor(record.level);
if (record.error == null) print(code.wrap(record.toString()));
if (record.error != null) {
var err = record.error;
if (err is AngelHttpException && err.statusCode != 500) return;
print(code.wrap(record.toString() + '\n'));
print(code.wrap(err.toString()));
if (record.stackTrace != null) {
print(code.wrap(record.stackTrace.toString()));
}
}
}
/// Chooses a color based on the logger [level].
AnsiCode chooseLogColor(Level level) {
if (level == Level.SHOUT)
return backgroundRed;
else if (level == Level.SEVERE)
return red;
else if (level == Level.WARNING)
return yellow;
else if (level == Level.INFO)
return cyan;
else if (level == Level.FINER || level == Level.FINEST) return lightGray;
return resetAll;
}

View file

@ -17,8 +17,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
await app.configure(controllers.configureServer); await app.configure(controllers.configureServer);
// Render `views/hello.jl` when a user visits the application root. // Render `views/hello.jl` when a user visits the application root.
app.get( app.get('/', (req, res) => res.render('hello'));
'/', (RequestContext req, ResponseContext res) => res.render('hello'));
// Mount static server at web in development. // Mount static server at web in development.
// The `CachingVirtualDirectory` variant of `VirtualDirectory` also sends `Cache-Control` headers. // The `CachingVirtualDirectory` variant of `VirtualDirectory` also sends `Cache-Control` headers.
@ -30,7 +29,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
// * https://medium.com/the-angel-framework/serving-static-files-with-the-angel-framework-2ddc7a2b84ae // * https://medium.com/the-angel-framework/serving-static-files-with-the-angel-framework-2ddc7a2b84ae
// * https://github.com/angel-dart/static // * https://github.com/angel-dart/static
if (!app.isProduction) { if (!app.isProduction) {
var vDir = new VirtualDirectory( var vDir = VirtualDirectory(
app, app,
fileSystem, fileSystem,
source: fileSystem.directory('web'), source: fileSystem.directory('web'),
@ -39,7 +38,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
} }
// Throw a 404 if no route matched the request. // Throw a 404 if no route matched the request.
app.fallback((req, res) => throw new AngelHttpException.notFound()); app.fallback((req, res) => throw AngelHttpException.notFound());
// Set our application up to handle different errors. // Set our application up to handle different errors.
// //

View file

@ -23,7 +23,7 @@ main() async {
TestClient client; TestClient client;
setUp(() async { setUp(() async {
var app = new Angel(); var app = Angel();
await app.configure(configureServer); await app.configure(configureServer);
client = await connectTo(app); client = await connectTo(app);