move / check into separat feature ("root")
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
25
server/cinema/lib/feature/root/root.service.dart
Normal file
25
server/cinema/lib/feature/root/root.service.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:cinema/feature/websocket/websocket.service.dart';
|
||||
import 'package:cinema/injectable.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:shelf/shelf.dart';
|
||||
import 'package:shelf_router/shelf_router.dart';
|
||||
|
||||
part 'root.service.g.dart';
|
||||
|
||||
@injectable
|
||||
class RootService {
|
||||
@Route.get('/')
|
||||
Future<Response> getRoot(Request request) async {
|
||||
final isWebSocket =
|
||||
request.headers['connection']?.toLowerCase() == 'upgrade' &&
|
||||
request.headers['upgrade']?.toLowerCase() == 'websocket';
|
||||
|
||||
if (isWebSocket) {
|
||||
return getIt<WebSocketService>().handler(request);
|
||||
}
|
||||
|
||||
return Response.ok('REST response');
|
||||
}
|
||||
|
||||
Router get router => _$RootServiceRouter(this);
|
||||
}
|
||||
Reference in New Issue
Block a user