platform/lib/src/routes/routes.dart

57 lines
1.8 KiB
Dart
Raw Normal View History

2016-04-22 02:56:21 +00:00
/// This app's route configuration.
library angel.routes;
2016-12-05 02:52:45 +00:00
import 'package:angel_cors/angel_cors.dart';
2016-12-21 19:06:09 +00:00
import 'package:angel_errors/angel_errors.dart';
2016-04-22 02:56:21 +00:00
import 'package:angel_framework/angel_framework.dart';
2016-11-23 22:30:41 +00:00
import 'package:angel_proxy/angel_proxy.dart';
2016-04-22 02:56:21 +00:00
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-12-05 02:52:45 +00:00
configureBefore(Angel app) async {
app.before.add(cors());
}
2016-06-23 21:54:10 +00:00
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-11-23 22:30:41 +00:00
await app.configure(new PubServeLayer());
await app.configure(new VirtualDirectory());
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-12-21 19:06:09 +00:00
// Set our application up to handle different errors.
var errors = new ErrorHandler(handlers: {
404: (req, res) async =>
res.render('error', {'message': 'No file exists at ${req.path}.'}),
500: (req, res) async => res.render('error', {'message': req.error.message})
2016-09-21 06:50:44 +00:00
});
2016-09-21 05:44:56 +00:00
2016-12-21 19:06:09 +00:00
errors.fatalErrorHandler = (AngelFatalError e) async {
e.request.response
..statusCode = 500
..writeln('500 Internal Server Error: ${e.error}')
..writeln(e.stack);
await e.request.response.close();
};
// Throw a 404 if no route matched the request
app.after.add(errors.throwError());
// Handle errors when they occur, based on outgoing status code.
// By default, requests will go through the 500 handler, unless
// they have an outgoing 200, or their status code has a handler
// registered.
app.after.add(errors.middleware());
// Pass AngelHttpExceptions through handler as well
await app.configure(errors);
2016-06-23 21:54:10 +00:00
}
configureServer(Angel app) async {
await configureBefore(app);
await configureRoutes(app);
2016-09-21 05:44:56 +00:00
await app.configure(Controllers.configureServer);
2016-06-23 21:54:10 +00:00
await configureAfter(app);
}