diff --git a/analysis_options.yaml b/analysis_options.yaml index 917f437b..1a46de2e 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,3 @@ analyzer: - strong-mode: true - exclude: - - .scripts-bin/**/*.dart + strong-mode: + implicit-casts: false diff --git a/bin/dev.dart b/bin/dev.dart index 2db404ea..5514cc7b 100644 --- a/bin/dev.dart +++ b/bin/dev.dart @@ -10,6 +10,7 @@ main() async { var hot = new HotReloader(() async { var app = new Angel()..lazyParseBodies = true; await app.configure(configureServer); + hierarchicalLoggingEnabled = true; app.logger = new Logger('angel'); var sub = app.logger.onRecord.listen(prettyLog); app.shutdownHooks.add((_) => sub.cancel()); diff --git a/bin/prod.dart b/bin/prod.dart index 0059c394..584c5817 100644 --- a/bin/prod.dart +++ b/bin/prod.dart @@ -1,4 +1,4 @@ -import 'dart:io' hide FileMode; +import 'dart:io'; import 'dart:isolate'; import 'package:angel/angel.dart'; import 'package:angel_framework/angel_framework.dart'; @@ -23,6 +23,7 @@ void isolateMain(int id) { app.configure(configureServer).then((_) async { // In production, we'll want to log errors to a file. // Alternatives include sending logs to a service like Sentry. + hierarchicalLoggingEnabled = true; app.logger = new Logger('angel') ..onRecord.listen((rec) { if (rec.error == null) { diff --git a/lib/angel.dart b/lib/angel.dart index e7183f50..e4c6f762 100644 --- a/lib/angel.dart +++ b/lib/angel.dart @@ -2,7 +2,6 @@ library angel; import 'dart:async'; -import 'package:angel_cors/angel_cors.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:file/local.dart'; import 'src/config/config.dart' as configuration; @@ -11,11 +10,12 @@ import 'src/services/services.dart' as services; /// Configures the server instance. Future configureServer(Angel app) async { - // Enable CORS - app.use(cors()); + // Grab a handle to the file system, so that we can do things like + // serve static files. + var fs = const LocalFileSystem(); // Set up our application, using the plug-ins defined with this project. - await app.configure(configuration.configureServer(const LocalFileSystem())); + await app.configure(configuration.configureServer(fs)); await app.configure(services.configureServer); - await app.configure(routes.configureServer(const LocalFileSystem())); + await app.configure(routes.configureServer(fs)); } diff --git a/lib/src/routes/routes.dart b/lib/src/routes/routes.dart index c816f8a3..44855b2d 100644 --- a/lib/src/routes/routes.dart +++ b/lib/src/routes/routes.dart @@ -1,6 +1,7 @@ /// This app's route configuration. library angel.src.routes; +import 'package:angel_cors/angel_cors.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_static/angel_static.dart'; import 'package:file/file.dart'; @@ -13,6 +14,9 @@ import 'controllers/controllers.dart' as controllers; /// * https://github.com/angel-dart/angel/wiki/Requests-&-Responses AngelConfigurer configureServer(FileSystem fileSystem) { return (Angel app) async { + // Enable CORS + app.use(cors()); + // Typically, you want to mount controllers first, after any global middleware. await app.configure(controllers.configureServer); @@ -21,7 +25,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) { '/', (RequestContext req, ResponseContext res) => res.render('hello')); // Mount static server at web in development. - // This variant of `VirtualDirectory` also sends `Cache-Control` headers. + // The `CachingVirtualDirectory` variant of `VirtualDirectory` also sends `Cache-Control` headers. // // In production, however, prefer serving static files through NGINX or a // similar reverse proxy. @@ -29,12 +33,14 @@ AngelConfigurer configureServer(FileSystem fileSystem) { // Read the following two sources for documentation: // * https://medium.com/the-angel-framework/serving-static-files-with-the-angel-framework-2ddc7a2b84ae // * https://github.com/angel-dart/static - var vDir = new CachingVirtualDirectory( - app, - fileSystem, - source: fileSystem.directory('web'), - ); - app.use(vDir.handleRequest); + if (!app.isProduction) { + var vDir = new VirtualDirectory( + app, + fileSystem, + source: fileSystem.directory('web'), + ); + app.use(vDir.handleRequest); + } // Throw a 404 if no route matched the request. app.use(() => throw new AngelHttpException.notFound()); diff --git a/pubspec.yaml b/pubspec.yaml index 0847bf0b..406f2a26 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ environment: homepage: https://github.com/angel-dart/angel dependencies: angel_auth: ^1.1.0 # Supports stateless authentication via JWT - angel_configuration: ^1.1.0 # Loads application configuration, along with support for .env files. + angel_configuration: ^1.2.0 # Loads application configuration, along with support for .env files. 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 @@ -16,5 +16,5 @@ dependencies: dev_dependencies: angel_hot: ^1.1.0 # Hot-reloading support. :) angel_test: ^1.1.0 # Utilities for testing Angel servers. - console: ^2.2.4 - test: ^0.12.13 \ No newline at end of file + console: ">=2.0.0 <4.0.0" + test: ^0.12.13