2016-04-22 02:56:21 +00:00
|
|
|
/// This app's route configuration.
|
|
|
|
library angel.routes;
|
|
|
|
|
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
import 'package:angel_static/angel_static.dart';
|
2016-07-05 21:11:54 +00:00
|
|
|
import 'controllers/controllers.dart' as Controllers;
|
2016-04-22 02:56:21 +00:00
|
|
|
|
2016-06-23 21:54:10 +00:00
|
|
|
configureBefore(Angel app) async {}
|
|
|
|
|
2016-04-22 02:56:21 +00:00
|
|
|
/// Put your app routes here!
|
2016-04-30 00:33:27 +00:00
|
|
|
configureRoutes(Angel app) async {
|
2016-04-22 02:56:21 +00:00
|
|
|
app.get('/', (req, ResponseContext res) => res.render('hello'));
|
2016-04-29 01:22:53 +00:00
|
|
|
app.all('*', serveStatic());
|
2016-06-23 21:54:10 +00:00
|
|
|
}
|
2016-04-22 02:56:21 +00:00
|
|
|
|
2016-06-23 21:54:10 +00:00
|
|
|
configureAfter(Angel app) async {
|
2016-04-29 01:22:53 +00:00
|
|
|
// 404 handler
|
|
|
|
app.after.add((RequestContext req, ResponseContext res) async {
|
2016-04-22 02:56:21 +00:00
|
|
|
res.willCloseItself = true;
|
|
|
|
res.status(404);
|
|
|
|
res.header('Content-Type', 'text/html');
|
2016-06-23 21:54:10 +00:00
|
|
|
res.underlyingResponse
|
|
|
|
.write(await app.viewGenerator('404', {'path': req.path}));
|
2016-04-22 02:56:21 +00:00
|
|
|
await res.underlyingResponse.close();
|
2016-04-29 01:22:53 +00:00
|
|
|
});
|
2016-06-23 21:54:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
configureServer(Angel app) async {
|
|
|
|
await configureBefore(app);
|
|
|
|
await configureRoutes(app);
|
|
|
|
await configureAfter(app);
|
|
|
|
}
|