24 lines
760 B
Dart
24 lines
760 B
Dart
import 'dart:io';
|
|
|
|
import 'package:shelf/shelf.dart';
|
|
import 'package:shelf/shelf_io.dart';
|
|
|
|
import 'router.dart';
|
|
import 'middleware/exception_handler.dart';
|
|
|
|
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 and handles exceptions.
|
|
final handler = Pipeline()
|
|
.addMiddleware(logRequests())
|
|
.addMiddleware(exceptionHandler())
|
|
.addHandler(createRouter().call);
|
|
|
|
// 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}');
|
|
}
|