This commit is contained in:
Tobe O 2018-07-15 00:25:28 -04:00
commit 40fcfe9ab2
6 changed files with 26 additions and 19 deletions

View file

@ -1,4 +1,3 @@
analyzer:
strong-mode: true
exclude:
- .scripts-bin/**/*.dart
strong-mode:
implicit-casts: false

View file

@ -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());

View file

@ -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) {

View file

@ -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));
}

View file

@ -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());

View file

@ -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
console: ">=2.0.0 <4.0.0"
test: ^0.12.13