2018-11-08 04:11:10 +00:00
|
|
|
import 'dart:io';
|
2021-05-14 10:34:09 +00:00
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
|
|
|
import 'package:angel3_framework/http.dart';
|
|
|
|
import 'package:angel3_framework/http2.dart';
|
2018-11-08 04:11:10 +00:00
|
|
|
import 'package:file/local.dart';
|
2018-12-14 02:31:21 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2018-11-08 04:11:10 +00:00
|
|
|
|
2021-05-14 10:34:09 +00:00
|
|
|
void main() async {
|
2019-05-02 22:48:31 +00:00
|
|
|
var app = Angel();
|
|
|
|
app.logger = Logger('angel')
|
2018-12-14 02:31:21 +00:00
|
|
|
..onRecord.listen((rec) {
|
|
|
|
print(rec);
|
|
|
|
if (rec.error != null) print(rec.error);
|
|
|
|
if (rec.stackTrace != null) print(rec.stackTrace);
|
|
|
|
});
|
2018-11-08 04:11:10 +00:00
|
|
|
|
2019-05-02 22:48:31 +00:00
|
|
|
var publicDir = Directory('example/public');
|
2018-11-08 04:11:10 +00:00
|
|
|
var indexHtml =
|
|
|
|
const LocalFileSystem().file(publicDir.uri.resolve('body_parsing.html'));
|
|
|
|
|
|
|
|
app.get('/', (req, res) => res.streamFile(indexHtml));
|
|
|
|
|
2018-12-09 15:49:59 +00:00
|
|
|
app.post('/', (req, res) => req.parseBody().then((_) => req.bodyAsMap));
|
2018-11-08 04:11:10 +00:00
|
|
|
|
2019-05-02 22:48:31 +00:00
|
|
|
var ctx = SecurityContext()
|
2018-11-08 04:11:10 +00:00
|
|
|
..useCertificateChain('dev.pem')
|
|
|
|
..usePrivateKey('dev.key', password: 'dartdart');
|
|
|
|
|
|
|
|
try {
|
|
|
|
ctx.setAlpnProtocols(['h2'], true);
|
|
|
|
} catch (e, st) {
|
2021-03-20 08:11:18 +00:00
|
|
|
app.logger!.severe(
|
2018-12-14 02:31:21 +00:00
|
|
|
'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.',
|
|
|
|
e,
|
|
|
|
st);
|
2018-11-08 04:11:10 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 22:48:31 +00:00
|
|
|
var http1 = AngelHttp(app);
|
|
|
|
var http2 = AngelHttp2(app, ctx);
|
2018-11-08 04:11:10 +00:00
|
|
|
|
|
|
|
// HTTP/1.x requests will fallback to `AngelHttp`
|
|
|
|
http2.onHttp1.listen(http1.handleRequest);
|
|
|
|
|
2021-07-08 02:42:40 +00:00
|
|
|
var server = await http2.startServer('127.0.0.1', 3000);
|
2018-11-08 04:11:10 +00:00
|
|
|
print('Listening at https://${server.address.address}:${server.port}');
|
|
|
|
}
|