platform/performance/hello/main.dart

37 lines
1 KiB
Dart
Raw Normal View History

/// A basic server that prints "Hello, world!"
library performance.hello;
import 'dart:io';
import 'dart:isolate';
import 'package:angel_framework/angel_framework.dart';
2017-09-22 14:53:49 +00:00
import 'package:logging/logging.dart';
main() {
for (int i = 0; i < Platform.numberOfProcessors - 1; i++)
Isolate.spawn(start, i + 1);
start(0);
}
void start(int id) {
var app = new Angel.custom(startShared)
..lazyParseBodies = true
..get('/', (req, res) => res.write('Hello, world!'))
..optimizeForProduction(force: true)
2017-09-22 14:53:49 +00:00
..logger = (new Logger('streaming_test')
..onRecord.listen((rec) {
print(rec);
if (rec.stackTrace != null) print(rec.stackTrace);
}));
var oldHandler = app.errorHandler;
app.errorHandler = (e, req, res) {
print('Oops: ${e.error ?? e}');
print(e.stackTrace);
return oldHandler(e, req, res);
};
app.startServer(InternetAddress.LOOPBACK_IP_V4, 3000).then((server) {
print(
'Instance #$id listening at http://${server.address.address}:${server.port}');
});
}