platform/packages/html/example/main.dart

48 lines
1.1 KiB
Dart
Raw Normal View History

2019-01-06 18:11:11 +00:00
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:angel_html/angel_html.dart';
import 'package:html_builder/elements.dart';
import 'package:logging/logging.dart';
2021-06-20 12:37:20 +00:00
void main() async {
var app = Angel();
var http = AngelHttp(app);
2019-01-06 18:11:11 +00:00
app.logger = Logger('angel_html')
..onRecord.listen((rec) {
print(rec);
if (rec.error != null) print(rec.error);
if (rec.stackTrace != null) print(rec.stackTrace);
});
app.fallback(renderHtml());
app.get('/html', (req, res) {
return html(c: [
head(c: [
title(c: [text('ok')])
])
]);
});
app.get(
'/strict',
chain([
renderHtml(
enforceAcceptHeader: true,
renderer: StringRenderer(
2021-06-20 12:37:20 +00:00
//doctype: null,
2019-01-06 18:11:11 +00:00
pretty: false,
),
),
(req, res) {
return div(c: [text('strict')]);
},
]),
);
app.fallback((req, res) => throw AngelHttpException.notFound());
await http.startServer('127.0.0.1', 3000);
print('Listening at ${http.uri}');
}