2018-11-10 21:48:03 +00:00
|
|
|
import 'dart:convert';
|
2021-05-15 10:45:39 +00:00
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
|
|
|
import 'package:angel3_framework/http.dart';
|
|
|
|
import 'package:angel3_jael/angel3_jael.dart';
|
2017-09-30 23:01:30 +00:00
|
|
|
import 'package:file/local.dart';
|
2021-12-25 02:40:30 +00:00
|
|
|
import 'package:jael3/jael3.dart';
|
2017-09-30 23:01:30 +00:00
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
|
|
|
|
main() async {
|
2021-05-15 10:45:39 +00:00
|
|
|
var app = Angel();
|
|
|
|
var http = AngelHttp(app);
|
2017-09-30 23:01:30 +00:00
|
|
|
var fileSystem = const LocalFileSystem();
|
|
|
|
|
|
|
|
await app.configure(
|
|
|
|
jael(fileSystem.directory('views')),
|
|
|
|
);
|
|
|
|
|
2018-11-10 21:48:03 +00:00
|
|
|
app.get(
|
|
|
|
'/',
|
|
|
|
(req, res) =>
|
|
|
|
res.render('index', {'title': 'Sample App', 'message': null}));
|
2017-10-01 05:00:14 +00:00
|
|
|
|
2018-12-10 17:45:16 +00:00
|
|
|
app.post('/', (req, res) async {
|
|
|
|
var body = await req.parseBody().then((_) => req.bodyAsMap);
|
2017-10-02 17:29:02 +00:00
|
|
|
print('Body: $body');
|
2017-10-01 05:00:14 +00:00
|
|
|
var msg = body['message'] ?? '<unknown>';
|
2017-10-02 17:29:02 +00:00
|
|
|
return await res.render('index', {
|
|
|
|
'title': 'Form Submission',
|
|
|
|
'message': msg,
|
2018-06-27 23:57:53 +00:00
|
|
|
'json_message': json.encode(msg),
|
2017-10-02 17:29:02 +00:00
|
|
|
});
|
2017-10-01 05:00:14 +00:00
|
|
|
});
|
2017-09-30 23:01:30 +00:00
|
|
|
|
2021-05-15 10:45:39 +00:00
|
|
|
app.fallback((req, res) => throw AngelHttpException.notFound());
|
2017-09-30 23:01:30 +00:00
|
|
|
|
2021-05-15 10:45:39 +00:00
|
|
|
app.logger = Logger('angel')
|
2017-09-30 23:01:30 +00:00
|
|
|
..onRecord.listen((rec) {
|
|
|
|
print(rec);
|
|
|
|
if (rec.error != null) print(rec.error);
|
|
|
|
if (rec.stackTrace != null) print(rec.stackTrace);
|
|
|
|
});
|
|
|
|
|
2018-11-10 21:48:03 +00:00
|
|
|
var server = await http.startServer('127.0.0.1', 3000);
|
2017-09-30 23:01:30 +00:00
|
|
|
print('Listening at http://${server.address.address}:${server.port}');
|
|
|
|
}
|