Server constructor
Server({
- required Iterable<
RouteNode> routes, - Map<
String, ServerFunctionBinding> functions = const <String, ServerFunctionBinding>{}, - Iterable<
Middleware> middleware = const <Middleware>[], - Iterable<
Module> modules()?, - InvocationModuleFactory? invocationModules,
- Iterable<
RouteNode> flutterRoutes = const <RouteNode>[], - Serializer? serializer,
- Renderer? renderer,
- ServerErrorHandler? onError,
- ServerCloseHandler? onClose,
- String functionPath = '/__odroe/functions',
- int maxFunctionPayload = defaultMaxFunctionPayload,
- int maxFunctionResponseFrameBytes = defaultMaxFunctionResponseFrameBytes,
- bool exposeErrors = false,
- bool allowRpcWithoutOrigin = false,
- Uri? publicOrigin,
Creates a server from explicitly selected routes and capabilities.
Implementation
Server({
required Iterable<RouteNode> routes,
Map<String, ServerFunctionBinding> functions =
const <String, ServerFunctionBinding>{},
Iterable<Middleware> middleware = const <Middleware>[],
Iterable<Module> Function()? modules,
this.invocationModules,
Iterable<RouteNode> flutterRoutes = const <RouteNode>[],
Serializer? serializer,
this.renderer,
ServerErrorHandler? onError,
ServerCloseHandler? onClose,
String functionPath = '/__odroe/functions',
this.maxFunctionPayload = defaultMaxFunctionPayload,
this.maxFunctionResponseFrameBytes = defaultMaxFunctionResponseFrameBytes,
this.exposeErrors = false,
this.allowRpcWithoutOrigin = false,
Uri? publicOrigin,
}) : publicOrigin = publicOrigin == null
? null
: validatePublicOrigin(publicOrigin),
routes = List<RouteNode>.unmodifiable(routes),
functions = Map<String, ServerFunctionBinding>.unmodifiable(functions),
middleware = List<Middleware>.unmodifiable(middleware),
modules = modules ?? _emptyModules,
serializer = serializer ?? Serializer(),
functionPath = normalizeFunctionPath(functionPath),
onError = onError ?? defaultServerErrorHandler,
_onClose = onClose,
_flutterRoutes = HashSet<Object>.identity()
..addAll(flutterRoutes.map((route) => route.identity)) {
if (maxFunctionPayload <= 0) {
throw ArgumentError.value(
maxFunctionPayload,
'maxFunctionPayload',
'Must be greater than zero.',
);
}
if (maxFunctionResponseFrameBytes < minimumFunctionResponseFrameBytes) {
throw ArgumentError.value(
maxFunctionResponseFrameBytes,
'maxFunctionResponseFrameBytes',
'Must be at least $minimumFunctionResponseFrameBytes bytes.',
);
}
_matcher = RouteMatcher(this.routes);
}