初始化项目
This commit is contained in:
23
bin/server.dart
Normal file
23
bin/server.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
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}');
|
||||
}
|
||||
Reference in New Issue
Block a user