onRequest method

  1. @override
void onRequest(
  1. SocketConnect connect
)
override

Overrides onRequest to handle OPTIONS..

Implementation

@override
void onRequest(SocketConnect connect) {
  var req = connect.request;
  if ('OPTIONS' == req.method) {
    var res = req.response;
    var headers = this.headers(connect);
    headers['Access-Control-Allow-Headers'] = 'Content-Type';
    headers.forEach((key, value) {
      res.headers.set(key, value);
    });
    res.statusCode = 200;

    connect.close();
  } else {
    super.onRequest(connect);
  }
}