Application
createApp() and the object it returns. For an introduction, see How it works.
createApp()
createApp() sets up the plugins, compiles the routes, runs the onInit hooks, mounts the routes on the adapter, then runs the onReady hooks. It does not start a server: call app.listen(), or hand the app to a serverless handler.
Options
The body size limit is an option of the adapter (bodyLimit, 1 MiB by default), or of a route. See Common options.
Startup errors
createApp() rejects, instead of starting with a wrong configuration, when:
adapteris missing;basePathandpublicBasePathare both set, or one is not a valid path;- two routes have the same method and path (
Route conflict: "GET /articles/:id" is already defined…); - a plugin is installed twice, depends on a plugin that is not installed, or the dependencies are circular;
- two plugins provide the same context key;
- the
corsoption is invalid, for instanceorigin: '*'withcredentials: true; - a
setup(),onInitoronReadyhook throws.
Route definitions are checked when they are declared: a path with unsupported syntax, an unknown method or an invalid status throws at defineRoute().
App
CORS options
origin accepts '*' (any origin, without credentials), an origin ('https://app.example.com'), a regular expression, a list of origins and regular expressions, or a function (origin, request) => boolean | Promise<boolean>.
See CORS for preflight requests and error responses.
Logger
The signature is the one of Pino: logger: pino() works as is. The default logger writes to the console:
See Logging.
For adapter authors
@dotpress/core also exports what an adapter needs: the HttpAdapter contract, CompiledRoute and DotpressRuntime, createRouteMatcher(), parseQueryString(), parseRequestBody(), DEFAULT_BODY_LIMIT, and for adapters built on the Web Request and Response, fromWebRequest(), readRequestBody() and toWebResponse(). The rules every adapter follows are documented on the HttpAdapter interface, and checked by the conformance suite.