AppConfig class

Constructors

AppConfig({required String appKey, List<String> previousKeys = const <String>[], int serverPort = 3000, List<int> additionalPorts = const <int>[], List<PortConfig> ports = const <PortConfig>[], String? host, int? totalIsolate, List<DoxProvider> providers = const <DoxProvider>[], List<DtoSchema<Object>> dtos = const <DtoSchema<Object>>[], MessageResolver? validationMessages, List globalMiddleware = const <dynamic>[], List<Router> routers = const <Router>[], void container(IocContainer c)?, CORSConfig cors = const CORSConfig(), LoggerConfig logger = const LoggerConfig(), CacheConfig cache = const CacheConfig(defaultStore: 'file', stores: <String, Map<String, dynamic>>{'file' : <String, dynamic>{'driver' : 'file', 'path' : 'storage/cache'}, 'memory' : <String, dynamic>{'driver' : 'memory'}}), SessionConfig session = const SessionConfig(), OpenApiConfig openApi = const OpenApiConfig(), ExceptionHandler exceptionHandler = const ExceptionHandler(), ResponseHandlerInterface? responseHandler, int maxBodySize = 10 * 1024 * 1024, int maxMultipartSize = 100 * 1024 * 1024, Duration bodyTimeout = const Duration(seconds: 120), Duration idleTimeout = const Duration(seconds: 30), int? maxConnections, bool http2 = false, int maxConcurrentStreams = 250, TlsOptions? tls, List<String> trustedProxies = const <String>[], bool compress = false, int compressLevel = 1, int fileThreads = 4, Duration shutdownTimeout = const Duration(seconds: 8), List<String>? webSocketAllowedOrigins, CoreFlags flags = const CoreFlags(), int computeWorkers = defaultComputeWorkers, StrictConfig strict = const StrictConfig(), bool htmlErrors = false, ErrorPageRenderer errorPage = defaultErrorPage})

Properties

additionalPorts → List<int>
More ports for the same app, eg. [8082]. Each isolate listens on serverPort and on each of these, with the same routes and the same settings (http2, tls, maxConnections and the other limits). One process serves all of them, so an app that needs two ports does not need a second process. With http2 on, each port takes HTTP/1.1 and HTTP/2. PORT in the env changes serverPort only. The test client (DoxTestClient) does not listen on these. Native server only. Default: none.
final
appKey → String
final
bodyTimeout → Duration
Idle time with no body bytes. A client that sends no request body bytes for this long gets 408 Request Timeout. A slow but steady upload is fine. It stops clients that hold a connection open. Native server only. Default 120 seconds.
final
cache → CacheConfig
cache stores for Cache(), see dox_cache
final
compress → bool
gzip responses on a Rust thread of the native server. Off by default. Streamed responses are not compressed. It costs CPU on every response. Let the proxy do it when you have one.
final
compressLevel → int
The gzip level of compress: 1 (the default) to 12. The server does not start with any other level.
final
computeWorkers → int
The number of worker isolates of Dox().compute (and Hash.makeAsync / Hash.verifyAsync). One pool for the whole process, shared by every server isolate. The workers start on the first task. More tasks than workers wait in line. Default defaultComputeWorkers. Must be 1 or more.
final
container → void Function(IocContainer c)?
Fills the container: registerContainer from lib/generated/container.g.dart. Every isolate runs it, so each one has its own instances. It also gives the routers, providers and model binders that dox_builder found.
final
cors → CORSConfig
final
dtos → List<DtoSchema<Object>>
Every DTO of the app: dtos from lib/generated/dtos.g.dart. Dox finds the DTO of a controller parameter and of req.validate<T>() with it.
final
errorPage → ErrorPageRenderer
Makes the HTML page of htmlErrors. Default: defaultErrorPage.
final
exceptionHandler → ExceptionHandler
Reports every error and turns it into a response. Extend ExceptionHandler to log to a tracker or change the answer.
final
fileThreads → int
Most threads that read the files of one folder of Route.staticFiles, from 1 to 64. All files that controllers return are one folder more. The threads start with the first file that the OS does not have in memory, and all isolates share them. More threads help a disk that is fast with many reads at once. Native server only.
final
flags → CoreFlags
Opt-in behaviors that change the defaults. All off by default. See CoreFlags.
final
globalMiddleware → List
final
hashCode → int
The hash code for this object.
no setterinherited
host → String?
The host (network interface) to listen on, like 127.0.0.1. Default: the env var APP_HOST, else all interfaces (IPv6 and IPv4).
final
htmlErrors → bool
Send an HTML error page to a browser. Off by default: every error is JSON. When on, a request that does not want JSON (see DoxRequest.expectsJson) gets a small HTML page with the status, like 404 Not Found. When APP_ENV is development or local, the page also shows the error text and the stack trace. API clients still get JSON. A validation error and an answer from a custom ExceptionHandler.render stay as they are.
final
http2 → bool
Let the same port also speak HTTP/2. HTTP/1.1 clients keep working on that port. Without tls it is HTTP/2 over plain TCP (h2c): use it behind a proxy that speaks h2c to the app (Caddy, nginx), eg. for gRPC. With tls, browsers and gRPC clients use HTTP/2 with no proxy. Native server only. Default false.
final
idleTimeout → Duration
A keep-alive connection with no new request for this long is closed. A request head must also come whole in this time. Behind a load balancer, set it longer than the idle timeout of the balancer (eg. 65 seconds for AWS ALB, which keeps connections for 60 seconds). Else Dox may close a connection the balancer still uses, and clients get 502. Default 30 seconds.
final
isDevelopment → bool
True when the env APP_ENV is development. Not set means production, so false. local is false too. It reads the env on each call, so it works before the server starts and in every isolate. Use it for config like prettyPrint or a database debug flag.
no setter
logger → LoggerConfig
final
maxBodySize → int
Max size in bytes of a JSON or urlencoded body, and the most a multipart body keeps in memory (a bigger file goes to a temp file). Bigger bodies get 413 Payload Too Large. Default 10 MB.
final
maxConcurrentStreams → int
The most open requests one HTTP/2 connection can have. Must be 1 or more. 0 or less throws an ArgumentError when the server starts. Only used when http2 is true. Native server only. Default 250.
final
maxConnections → int?
The most connections one isolate holds open at once. Must be 1 or more. 0 or less throws an ArgumentError when the server starts. When an isolate is full, it stops accepting until one closes. WebSocket connections and connections that are still closing count too. New clients wait in the OS listen queue. It holds up to 1024 clients, and the OS can make it smaller (somaxconn; 128 by default on macOS). When the queue is full, new clients wait and then time out. On Linux each new client goes to one isolate (SO_REUSEPORT), so it can wait for a full isolate even when others have room. The limit is per isolate and per port, so the whole app holds up to maxConnections * totalIsolate * (1 + additionalPorts.length + ports.length). Keep that below the file limit of the process (ulimit -n). Native server only. Default null: no limit.
final
maxMultipartSize → int
Max size in bytes of a multipart/form-data body (file uploads). Bigger bodies get 413 Payload Too Large. Default 100 MB.
final
openApi → OpenApiConfig
/docs, /openapi.json and /openapi.yaml, see dox_openapi
final
ports → List<PortConfig>
More ports for the same app, each with its own http2 and tls. Use it when one process must serve plain HTTP and HTTPS together, eg. HTTPS for the public and a plain port for a health check. Each isolate listens on serverPort, on the additionalPorts and on each of these, with the same routes. http2 and tls are not used for these ports: each PortConfig has its own. The limits (maxConnections, idleTimeout and the others) are the ones of the app. req.scheme() is https only for a request that came on a port with tls. A port that is listed two times throws an ArgumentError when the server starts. The test client (DoxTestClient) does not listen on these. Native server only. Default: none.
final
previousKeys → List<String>
Old APP_KEYs, to change the key without logging out every user. Encrypted cookies and cookie sessions made with one of them can still be read. New ones are made with appKey only. Remove an old key once its cookies have expired.
final
providers → List<DoxProvider>
Providers to run at start, in every isolate. You can leave it empty: every class that extends DoxProvider is in lib/generated/container.g.dart. A provider listed here runs first.
final
responseHandler → ResponseHandlerInterface?
final
routers → List<Router>
Routers to register. You can leave it empty: every class that extends Router is in lib/generated/container.g.dart. A router listed here comes first, in this order.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serverPort → int
The port to listen on. Default 3000. When the env has no APP_PORT but has PORT (Cloud Run, Fly, Render, Heroku set it), Dox listens on PORT instead.
final
session → SessionConfig
session settings for SessionMiddleware. Cookie driver by default.
final
shutdownTimeout → Duration
On SIGTERM or SIGINT the server stops taking new connections, and waits this long for open requests to finish. Then it closes the rest, runs shutdown() of every provider and exits. Default 8 seconds. Keep it below the kill timeout of your platform (docker stop: 10 seconds).
final
strict → StrictConfig
Warnings for code that blocks the server, for development. Off by default. See StrictConfig.
final
tls → TlsOptions?
Serve HTTPS on the port, with no proxy: the certificate chain and its private key, as PEM files. The port then speaks only TLS (1.2 and 1.3). A plain HTTP client gets no answer. With http2 on, the client picks HTTP/2 or HTTP/1.1 in the handshake (ALPN). req.scheme() is https, so cookies get Secure. A bad file throws a TlsException when the server starts. Dox().server.reloadCertificate() reads the files again, with no restart. For HTTPS on one port and plain HTTP on another, see ports. Native server only. Default null: plain HTTP.
final
totalIsolate → int
Isolates that serve HTTP. Default: Processors.available.
final
trustedProxies → List<String>
IPs or CIDR ranges of reverse proxies (nginx, Caddy, load balancer) that Dox trusts. Only when the direct client is in this list does Dox read X-Forwarded-For for req.ip() and X-Forwarded-Proto for req.scheme(). Use ['*'] to trust any direct client, but only the last X-Forwarded-For hop (only safe when the app port is not reachable from outside). Empty by default.
final
validationMessages → MessageResolver?
Messages for validation errors, for example in other languages. Default: the English messages.
final
webSocketAllowedOrigins → List<String>?
Turns on the Origin check for every Route.websocket route. Off (null) by default: any site can open a socket from a browser, with the cookies of the user. Set it to only allow pages of the same host and the sites in the list, like ['https://app.example.com']. [] means the same host only. Other origins get 403. The allowedOrigins of a route wins over this.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

defaultComputeWorkers → const int
The default of computeWorkers: 4. Enough for a few password hashes at the same time, small enough for a small server. More workers than CPU cores do not make CPU work faster.