DefaultRouter constructor
DefaultRouter({})
The constructor.
uriMapping
- The key can be a String or RegExp instance. If String, an instance ofRegExp('^$pattern\$')
will be generated and used. Refer to map for details.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<Pattern, 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) {
if (!handler.startsWith('/'))
throw ServerError("URI must start with '/'; not '$handler'");
} else if (handler is! Function) {
throw ServerError("Error mapping: function (renderer) or string (URI) is required for $code");
}
_errorMapping[code] = handler;
});
}