mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
This reverts commit fc6222ebc8.
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:shared/shared.dart';
|
||||
import 'package:shelf/shelf.dart';
|
||||
import 'package:shelf/shelf_io.dart';
|
||||
import 'package:shelf_router/shelf_router.dart';
|
||||
|
||||
int count = 0;
|
||||
|
||||
// Configure routes.
|
||||
final _router = Router()
|
||||
..post('/', _incrementHandler)
|
||||
..get('/', _getValueHandler);
|
||||
|
||||
Future<Response> _incrementHandler(Request request) async {
|
||||
final incr = Increment.fromJson(json.decode(await request.readAsString()));
|
||||
count += incr.by;
|
||||
return Response.ok(json.encode(Count(count).toJson()));
|
||||
}
|
||||
|
||||
Response _getValueHandler(Request request) =>
|
||||
Response.ok(json.encode(Count(count).toJson()));
|
||||
|
||||
void main(List<String> args) async {
|
||||
// Use any available host or container IP (usually `0.0.0.0`).
|
||||
final ip = InternetAddress.anyIPv4;
|
||||
|
||||
// Configure a pipeline that logs requests.
|
||||
final handler = Pipeline().addMiddleware(logRequests()).addHandler(_router);
|
||||
|
||||
// For running in containers, we respect the PORT environment variable.
|
||||
final port = int.parse(Platform.environment['PORT'] ?? '8080');
|
||||
final server = await serve(handler, ip, port);
|
||||
print('Server listening on port ${server.port}');
|
||||
}
|
||||
Reference in New Issue
Block a user