platform/packages/user_agent/angel_user_agent/example/example.dart

28 lines
777 B
Dart
Raw Normal View History

2018-09-11 21:21:06 +00:00
import 'dart:io';
2021-06-21 05:43:02 +00:00
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';
import 'package:angel3_user_agent/angel3_user_agent.dart';
import 'package:user_agent_analyzer/user_agent_analyzer.dart';
2018-09-11 21:21:06 +00:00
2021-06-20 12:37:20 +00:00
void main() async {
2021-02-14 05:22:25 +00:00
var app = Angel();
var http = AngelHttp(app);
2018-09-11 21:21:06 +00:00
2021-06-21 06:16:06 +00:00
//TODO: To be reviewed
2018-09-11 21:21:06 +00:00
app.get(
'/',
waterfall([
parseUserAgent,
(req, res) {
2021-06-21 06:16:06 +00:00
var ua = req.container.make<UserAgent>() as UserAgent;
2018-09-11 21:21:06 +00:00
return ua.isChrome
? 'Woohoo! You are running Chrome.'
: 'Sorry, we only support Google Chrome.';
},
]),
);
var server = await http.startServer(InternetAddress.anyIPv4, 3000);
print('Listening at http://${server.address.address}:${server.port}');
}