diff --git a/.vscode/launch.json b/.vscode/launch.json index 85f97b3..ab26e08 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,14 +3,14 @@ "configurations": [ { "name": "Development Server", - "type": "dart-cli", + "type": "dart", "request": "launch", "program": "${workspaceRoot}/bin/dev.dart", "checkedMode": true }, { "name": "Production Server", - "type": "dart-cli", + "type": "dart", "request": "launch", "program": "${workspaceRoot}/bin/prod.dart", "checkedMode": true diff --git a/Dockerfile b/Dockerfile index cf64b4e..0a70a02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,20 @@ -FROM ubuntu:14.04 +FROM ubuntu:16.04 MAINTAINER Tobe O -# Install Dart SDK 1.24.2 +# Install Dart SDK. RUN sudo apt-get update RUN sudo apt-get install -y apt-transport-https RUN sudo apt-get install -y curl RUN sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -' -RUN sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list' + +# Uncomment this for Dart 1.24.x +# RUN sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list' + +# Comment this out if not installing Dart 2.x +RUN sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_unstable.list > /etc/apt/sources.list.d/dart_unstable.list' + RUN sudo apt-get update -RUN sudo apt-get install -y dart=1.24.2-1 +RUN sudo apt-get install -y dart RUN export PATH="/usr/lib/dart/bin:$PATH" # Copy necessary files diff --git a/README.md b/README.md index e0ab82c..953eec1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/angel_dart/discussion) [![Pub](https://img.shields.io/pub/v/angel_framework.svg)](https://pub.dartlang.org/packages/angel_framework) +[![Build status](https://travis-ci.org/angel-dart/framework.svg?branch=master)](https://travis-ci.org/angel-dart/framework) +![License](https://img.shields.io/github/license/angel-dart/framework.svg) **Fill out the [v1.0.0 survey](https://docs.google.com/forms/d/e/1FAIpQLSfEgBNsOoi_nYZMmg2IAGyMv1nNaa6B3kUk3QdNJU5987ucVA/viewform?usp=sf_link) now!!!** diff --git a/bin/prod.dart b/bin/prod.dart index 3113e83..641e128 100644 --- a/bin/prod.dart +++ b/bin/prod.dart @@ -1,7 +1,8 @@ -import 'dart:io'; +import 'dart:io' hide FileMode; import 'dart:isolate'; import 'package:angel/angel.dart'; import 'package:angel_framework/angel_framework.dart'; +import 'package:dart2_constant/io.dart'; import 'package:logging/logging.dart'; const String hostname = '127.0.0.1'; @@ -25,8 +26,11 @@ void isolateMain(int id) { app.logger = new Logger('angel') ..onRecord.listen((rec) { if (rec.error != null) { - var sink = - new File('server_log.txt').openWrite(mode: FileMode.APPEND); + var err = rec.error; + if (err is AngelHttpException && err.statusCode != 500) return; + var now = new DateTime.now().toUtc(); + var filename = 'server_log_' + now.toString() + '.txt'; + var sink = new File(filename).openWrite(mode: FileMode.append); sink ..writeln(rec.error) ..writeln(rec.stackTrace) diff --git a/lib/src/pretty_logging.dart b/lib/src/pretty_logging.dart index 7602099..625ca12 100644 --- a/lib/src/pretty_logging.dart +++ b/lib/src/pretty_logging.dart @@ -1,3 +1,4 @@ +import 'package:angel_http_exception/angel_http_exception.dart'; import 'package:console/console.dart'; import 'package:logging/logging.dart'; @@ -5,13 +6,17 @@ import 'package:logging/logging.dart'; void prettyLog(LogRecord record) { var pen = new TextPen(); chooseLogColor(pen.reset(), record.level); - pen(record.toString()); - - if (record.error != null) - pen(record.error.toString()); - if (record.stackTrace != null) - pen(record.stackTrace.toString()); - + + if (record.error == null) pen(record.toString()); + + if (record.error != null) { + var err = record.error; + if (err is AngelHttpException && err.statusCode != 500) return; + pen(record.toString() + '\n'); + pen(err.toString()); + if (record.stackTrace != null) pen(record.stackTrace.toString()); + } + pen(); } @@ -27,6 +32,5 @@ void chooseLogColor(TextPen pen, Level level) { pen.magenta(); else if (level == Level.FINER) pen.blue(); - else if (level == Level.FINEST) - pen.darkBlue(); + else if (level == Level.FINEST) pen.darkBlue(); } diff --git a/lib/src/routes/routes.dart b/lib/src/routes/routes.dart index bbdd8ad..c816f8a 100644 --- a/lib/src/routes/routes.dart +++ b/lib/src/routes/routes.dart @@ -43,13 +43,19 @@ AngelConfigurer configureServer(FileSystem fileSystem) { // // Read the following for documentation: // * https://github.com/angel-dart/angel/wiki/Error-Handling - app.errorHandler = (e, req, res) async { - if (e.statusCode == 404) { - return await res - .render('error', {'message': 'No file exists at ${req.path}.'}); - } - return await res.render('error', {'message': e.message}); + var oldErrorHandler = app.errorHandler; + app.errorHandler = (e, req, res) async { + if (!req.accepts('text/html')) + return await oldErrorHandler(e, req, res); + else { + if (e.statusCode == 404) { + return await res + .render('error', {'message': 'No file exists at ${req.path}.'}); + } + + return await res.render('error', {'message': e.message}); + } }; }; } diff --git a/pubspec.yaml b/pubspec.yaml index d4f021d..0847bf0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: angel description: An easily-extensible web server framework in Dart. publish_to: none # Ensure we don't accidentally publish our private code! ;) environment: - sdk: '>=2.0.0-dev <2.0.0' + sdk: '>=2.0.0-dev <3.0.0' homepage: https://github.com/angel-dart/angel dependencies: angel_auth: ^1.1.0 # Supports stateless authentication via JWT @@ -10,14 +10,11 @@ dependencies: angel_cors: ^1.0.0 # CORS support angel_framework: ^1.1.0 # The core server library. angel_jael: ^1.0.0 # Server-side templating engine - angel_serialize: ^2.0.0 # Model definition metadata. angel_static: ^1.3.0 # Static file server angel_validate: ^1.0.0 # Allows for validation of input data + dart2_constant: ^1.0.0 # For backwards compatibility. dev_dependencies: - angel_hot: ^1.1.0-alpha # Hot-reloading support. :) - angel_serialize_generator: ^2.0.0 # Generates serialization code for models. + angel_hot: ^1.1.0 # Hot-reloading support. :) angel_test: ^1.1.0 # Utilities for testing Angel servers. - build_runner: ^0.7.0 console: ^2.2.4 - grinder: ^0.8.0 test: ^0.12.13 \ No newline at end of file diff --git a/tool/grind.dart b/tool/grind.dart deleted file mode 100644 index d26a26a..0000000 --- a/tool/grind.dart +++ /dev/null @@ -1,21 +0,0 @@ -// Grinder is not part of Angel, but you may consider using it -// to run tasks, a la Gulp. -// -// See its documentation here: -// https://github.com/google/grinder.dart - -import 'package:grinder/grinder.dart'; - -main(args) => grind(args); - -@Task() -test() => new TestRunner().testAsync(); - -@DefaultTask() -@Depends(test) -build() { - Pub.build(); -} - -@Task() -clean() => defaultClean(); \ No newline at end of file