35 lines
1.1 KiB
Dart
35 lines
1.1 KiB
Dart
import 'package:angel3_framework/angel3_framework.dart';
|
|
import 'package:angel3_framework/http.dart';
|
|
import 'package:angel3_container/mirrors.dart';
|
|
import 'package:angel3_pipeline/pipeline.dart';
|
|
|
|
class GreetingPipe {
|
|
dynamic handle(String input, Function next) {
|
|
return next('Hello, $input');
|
|
}
|
|
}
|
|
|
|
void main() async {
|
|
var app = Angel(reflector: MirrorsReflector());
|
|
var http = AngelHttp(app);
|
|
|
|
app.container.registerSingleton((c) => Pipeline(c));
|
|
|
|
app.get('/', (req, res) async {
|
|
var pipeline = app.container.make<Pipeline>();
|
|
var result = await pipeline.send('World').through([
|
|
'GreetingPipe',
|
|
(String input, Function next) => next('$input!'),
|
|
(String input, Function next) async {
|
|
await Future.delayed(Duration(seconds: 1));
|
|
return next(input.toUpperCase());
|
|
},
|
|
]).then((result) => 'Final result: $result');
|
|
|
|
res.write(
|
|
result); // Outputs: "Final result: HELLO, WORLD!" (after 1 second)
|
|
});
|
|
|
|
await http.startServer('localhost', 3000);
|
|
print('Server started on http://localhost:3000');
|
|
}
|