platform/packages/html/example/main.dart
2024-10-12 18:45:27 -07:00

47 lines
1.1 KiB
Dart

import 'package:protevus_framework/protevus_framework.dart';
import 'package:protevus_framework/http.dart';
import 'package:protevus_html/protevus_html.dart';
import 'package:belatuk_html_builder/elements.dart';
import 'package:logging/logging.dart';
void main() async {
var app = Protevus();
var http = ProtevusHttp(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 ProtevusHttpException.notFound());
await http.startServer('127.0.0.1', 3000);
print('Listening at ${http.uri}');
}