dynamicCors function

Future<bool> Function(RequestContext, ResponseContext) dynamicCors (
  1. FutureOr<CorsOptions> f(
    1. RequestContext,
    2. ResponseContext
    )
)

On-the-fly configures the cors handler. Use this when the context of the surrounding request is necessary to decide how to handle an incoming request.

Implementation

Future<bool> Function(RequestContext, ResponseContext) dynamicCors(
    FutureOr<CorsOptions> Function(RequestContext, ResponseContext) f) {
  return (req, res) async {
    var opts = await f(req, res);
    var handler = cors(opts);
    return await handler(req, res);
  };
}