platform/packages/html/example/main.dart
Tobe O a584b8ce02 Add 'packages/html/' from commit '62d29b45fde6a235a24b280c461d35bf1158585e'
git-subtree-dir: packages/html
git-subtree-mainline: 5834fbe416
git-subtree-split: 62d29b45fd
2020-02-15 18:28:52 -05:00

46 lines
1 KiB
Dart

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';
main() async {
var app = Angel(), http = AngelHttp(app);
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(
doctype: null,
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}');
}