This commit is contained in:
regiostech 2016-04-28 21:22:53 -04:00
parent 77af2aa8e4
commit e9875f6f20
4 changed files with 12 additions and 10 deletions

View file

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

View file

@ -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<Angel> createServer() async {
Angel app = new Angel();
app.configure(configureServer);
await app.configure(configureServer);
return app;
}

View file

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

View file

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