diff --git a/bin/server.dart b/bin/server.dart index bd213ea..3c391da 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 745e172..59f35b7 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 5ae1efd..a8e52a3 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 aedf4c1..723a3d8 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