dartaqueduct

Aqueduct ignores conroller


I have two controllers, one resource, the other normal. They are in the same thread and both must run.

I deliberately inserted a sudden return in a normal controller to make sure it was simply ignored.

Regular controller:

import 'package:aqueduct/aqueduct.dart';
import 'package:app_server/app_server.dart';

class InputController extends Controller {
  @override
  Future<RequestOrResponse> handle(Request request) async {
    return Response.badRequest();
  }
}

Channel:

@override
  Controller get entryPoint {
    final router = Router();
    
    router.route("/auth/[:type]")
      ..link(() => InputController())
      ..link(() => AuthorizationController(context));
    
    return router;

  }

The channel skips the InputController, and immediately proceeds to the resource controller (AuthorizationController).


Solution

  • In fact it does not skip the InputController (you can printf inside if you want to belive :) ), but it works on the object returned by router.route("/auth/[:type]") instead of on the result of InputController.

    In other words, your channel can be written as below:

    @override
      Controller get entryPoint {
        final router = Router();
        
        var router2 = router.route("/auth/[:type]");
          router2 = router2.link(() => InputController())
          router2 = router2.link(() => AuthorizationController(context));
        
        return router;
    
      }
    

    Change cascade notation to a normal chain in the channel in order to resolve tour problem:

    @override
      Controller get entryPoint {
        final router = Router();
        
        router.route("/auth/[:type]")
          .link(() => InputController())
          .link(() => AuthorizationController(context));
        
        return router;
    
      }