DefaultRouter constructor

DefaultRouter({
  1. Map<String, dynamic>? uriMapping,
  2. Map<int, dynamic>? errorMapping,
  3. Map<String, RequestFilter>? filterMapping,
  4. int cacheSize = 1000,
  5. bool protectRSP = true,
})

The constructor. *

    • cacheSize - the size of the cache for speeding up URI matching.
    • protectRSP - protects RSP files from accessing at the client.
  • You can specify it to false if you don't put RSP files with client
  • resource files.

Implementation

DefaultRouter({Map<String, dynamic>? uriMapping,
    Map<int, dynamic>? errorMapping,
    Map<String, RequestFilter>? filterMapping,
    int cacheSize = 1000, bool protectRSP = true}): _cacheSize = cacheSize {

  if (uriMapping != null)
    uriMapping.forEach(map);

  //default mapping
  if (protectRSP)
    _uriMapping.add(_UriMapping("/.*[.]rsp(|[.][^/]*)", _f404));
      //prevent .rsp and .rsp.* from access

  if (filterMapping != null)
    filterMapping.forEach(filter);

  if (errorMapping != null)
    errorMapping.forEach((code, handler) {
      final handler = errorMapping[code];
      if (handler is String) {
        String uri = handler;
        if (!uri.startsWith('/'))
          throw ServerError("URI must start with '/'; not '$uri'");
      } else if (handler is! Function) {
        throw ServerError("Error mapping: function (renderer) or string (URI) is required for $code");
      }

      _errorMapping[code] = handler;
    });
}