create method
Future<DartnessServer>
create({
- Iterable<
DartnessController> controllers = const [], - Iterable<
DartnessMiddleware> middlewares = const [], - Iterable<
DartnessInterceptor> interceptors = const [], - Iterable<
DartnessErrorHandler> errorHandlers = const [], - DartnessApplicationOptions? options,
Starts the _server
.
If logRequest
is true prints the time of the request, the elapsed time for the
inner handlers, the response's status code and the request URI.
Implementation
Future<DartnessServer> create({
final Iterable<DartnessController> controllers = const [],
final Iterable<DartnessMiddleware> middlewares = const [],
final Iterable<DartnessInterceptor> interceptors = const [],
final Iterable<DartnessErrorHandler> errorHandlers = const [],
final DartnessApplicationOptions? options,
}) async {
_options = options ?? DartnessApplicationOptions();
_server = DefaultDartnessServer(
_options.port,
internetAddress: _options.internetAddress,
);
for (final controller in controllers) {
_addController(controller);
}
for (final middleware in middlewares) {
_addMiddleware(middleware);
}
for (final interceptor in interceptors) {
_addInterceptor(interceptor);
}
for (final errorHandler in errorHandlers) {
_addErrorHandler(errorHandler);
}
if (options?.logRequest == true) {
_addInterceptor(LogRequestsInterceptor());
}
await _server.start();
print('Server listening on port ${_server.getPort()}');
return _server;
}