1

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).

Spasibo
  • 144
  • 7

1 Answers1

1

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;

  }
Owczar
  • 2,335
  • 1
  • 17
  • 24
  • Oh God. The whole problem was in unnecessary points... Thank you, I still need to study in this topic. – Spasibo Nov 24 '20 at 14:25