From e9875f6f20ff07e54f05b99ae85179ce160dfae2 Mon Sep 17 00:00:00 2001 From: regiostech Date: Thu, 28 Apr 2016 21:22:53 -0400 Subject: [PATCH] :) --- bin/server.dart | 2 +- lib/angel.dart | 5 +++-- lib/src/config/config.dart | 8 ++++---- lib/src/config/routes.dart | 7 ++++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/bin/server.dart b/bin/server.dart index bd213ea3..3c391da9 100644 --- a/bin/server.dart +++ b/bin/server.dart @@ -4,7 +4,7 @@ import 'package:angel/angel.dart'; import 'package:angel_framework/angel_framework.dart'; main() async { - Angel app = createServer(); + Angel app = await createServer(); runZoned(() async { await app.startServer( diff --git a/lib/angel.dart b/lib/angel.dart index 745e1722..59f35b76 100644 --- a/lib/angel.dart +++ b/lib/angel.dart @@ -1,14 +1,15 @@ /// Your very own web application! library angel; +import 'dart:async'; import 'package:angel_framework/angel_framework.dart'; import 'src/config/config.dart' show configureServer; /// Creates and configures the server instance. -Angel createServer() { +Future createServer() async { Angel app = new Angel(); - app.configure(configureServer); + await app.configure(configureServer); return app; } \ No newline at end of file diff --git a/lib/src/config/config.dart b/lib/src/config/config.dart index 5ae1efd2..a8e52a39 100644 --- a/lib/src/config/config.dart +++ b/lib/src/config/config.dart @@ -7,8 +7,8 @@ import 'package:angel_framework/angel_framework.dart'; import 'package:angel_mustache/angel_mustache.dart'; import 'routes.dart'; -configureServer(Angel app) { - app.configure(loadConfigurationFile()); - app.configure(mustache(new Directory('views'))); - app.configure(configureRoutes); +configureServer(Angel app) async { + await app.configure(loadConfigurationFile()); + await app.configure(mustache(new Directory('views'))); + await app.configure(configureRoutes); } \ No newline at end of file diff --git a/lib/src/config/routes.dart b/lib/src/config/routes.dart index aedf4c18..723a3d83 100644 --- a/lib/src/config/routes.dart +++ b/lib/src/config/routes.dart @@ -7,14 +7,15 @@ import 'package:angel_static/angel_static.dart'; /// Put your app routes here! configureRoutes(Angel app) { app.get('/', (req, ResponseContext res) => res.render('hello')); - app.get('*', serveStatic()); + app.all('*', serveStatic()); - app.on404 = (RequestContext req, ResponseContext res) async { + // 404 handler + app.after.add((RequestContext req, ResponseContext res) async { res.willCloseItself = true; res.status(404); res.header('Content-Type', 'text/html'); res.underlyingResponse.write( await app.viewGenerator('404', {'path': req.path})); await res.underlyingResponse.close(); - }; + }); } \ No newline at end of file