Skip to main content

Configuration

Overviewā€‹

This document describes configuration options available for a reSolve application.

In a new reSolve application, configuration settings are split across the following files for different run targets:

  • config.app.js - Contains general app configuration settings. In this file, you should register the application's aggregates, Read Models and View Models.
  • config.cloud.js - Contains configuration settings that target the reSolve Cloud environment.
  • config.dev.js - Contains configuration settings that target the development server.
  • config.prod.js - Contains configuration settings that target the production server.
  • config.test_functional.js - Contains configuration settings that target the test environment.

All these options are merged into a global configuration object and passed to a run script based on the logic defined in the run.js file:

import {
...
watch,
...
} from '@resolve-js/scripts'
...
switch (launchMode) {
...
case 'dev': {
const resolveConfig = merge(baseConfig, devConfig)
await watch(resolveConfig)
break
}
...
}

Refer to the JSON schema file to familiarize yourself with the definition of the configuration object's structure.

Referenceā€‹

aggregatesā€‹

An array of the application's aggregates. An aggregate configuration object within this array contains the following fields:

FieldDescription
nameThe aggregate's name.
commandsA path to a file that defines aggregate commands.
projectionA path to a file that defines aggregate projection.
serializeStateA path to a file that defines a state serializer function.
deserializeStateA path to a file that defines a state deserializer function.
encryptionA path to a file that defines data encryption and decryption logic.
aggregates: [
{
name: 'ShoppingList',
commands: 'common/aggregates/shopping_list.commands.js',
projection: 'common/aggregates/shopping_list.projection.js',
},
]

apiHandlersā€‹

Specifies an array of the application's API Handlers. An API handler configuration object within this array contains the following fields:

FieldDescription
pathThe URL path for which the handler is invoked. The path is specified in the route-trie router's format.
handlerThe path to the file that contains the handler's definition.
methodThe HTTP method to handle.

Example:ā€‹

apiHandlers: [
{
path: '/api/uploader/getFileUrl',
handler: 'common/api-handlers/getFileUrl.js',
method: 'GET',
},
]

clientEntriesā€‹

Specifies an array of the client application script's entry points. The entry point is specified as a path to a JavaScript file. The file should export a function that takes a resolveContext as a parameter.

client/index.js:ā€‹

const main = async resolveContext => {
...
}
export default main

config.app.js:ā€‹

clientEntries: ['client/index.js']

In this section, you can also specify an array of Server Side Rendering (SSR) scripts that target different environments:

clientEntries: [
'client/index.js',
[
'client/ssr.js',
{
outputFile: 'common/local-entry/ssr.js',
moduleType: 'commonjs',
target: 'node',
},
],
[
'client/ssr.js',
{
outputFile: 'common/cloud-entry/ssr.js',
moduleType: 'commonjs',
target: 'node',
},
],
]

Each entry in this array should specify the path to the SSR script and a configuration object with the following fields:

FieldDescription
outputFileThe path to a file in which to place the SSR script for the current environment.
moduleTypeThe type of a chunk generated by SSR.
targetThe type of the environment that will run the script.

The following module type options are available:

  • 'iife' - A chunk that contains an Immediately Invoked Function Expression (IIFE).
  • 'commonjs' - A chunk in the CommonJS module format.
  • 'esm' - A chunk in the ECMAScript module format.

The following target options are available:

  • 'web' - The client will run the script.
  • 'node' - The server will run the script.

To serve SSR markup to the client, you need to register the live-require-handler.js API handler in the apiHandlers configuration section:

config.app.js:ā€‹

...
apiHandlers: [
{
handler: {
module: {
package: '@resolve-js/runtime-base',
import: 'liveRequireHandler',
},
options: {
modulePath: './ssr.js',
moduleFactoryImport: false
}
},
path: '/:markup*',
method: 'GET'
}
],
...

clientImportsā€‹

Specifies JavaScript files within the project, whose exports should be passed to the client script through the client entry point's parameter.

The configuration object should be an array of file paths.

distDirā€‹

Specifies the project directory where compiled distributable files are saved.

eventstoreAdapterā€‹

Specifies an adapter used to connect to to the application's event store. An adapter configuration object contains the following fields:

FieldDescription
moduleThe name of a module or the path to a file that defines an adapter.
optionsAn object that defines the adapter's options as key-value pairs.

Example:ā€‹

eventstoreAdapter: {
module: '@resolve-js/eventstore-lite',
options: {
databaseFile: ':memory:'
}
}

The following adapters are available:

Adapter ModuleDescription
@resolve-js/eventstore-liteUsed to store events in an SQLite database.
@resolve-js/eventstore-mysqlUsed to store events in a MySQL database.
@resolve-js/eventstore-postgresqlUsed to store events in a PostgreSQL database.

eventstore-liteā€‹

Used to store events in an SQLite database.

This adapter supports the following options:

Option NameDescription
databaseFileSpecifies the path to a database file used to store events. If set to ':memory:', all data is stored in memory and is lost when the application is shut down or restarted.
secretsTableNameThe name of a database table used to store secrets.
snapshotBucketSizeThe number of events between aggregate snapshots.
Exampleā€‹
const prodConfig = {
eventstoreAdapter: {
module: '@resolve-js/eventstore-lite',
options: {
databaseFile: 'data/event-store.db'
// databaseFile: ':memory:'
},
},
...
}

eventstore-mysqlā€‹

Used to store events in a MySQL database.

To configure the database connection for this adapter, specify MySQL connection setting as the adapter's options. Additionally, you can specify the following options:

Option NameDescription
eventsTableNameThe name of a database table used to store events.
secretsTableNameThe name of a database table used to store secrets.
snapshotBucketSizeThe number of events between aggregate snapshots.
Exampleā€‹
const prodConfig = {
eventstoreAdapter: {
module: '@resolve-js/eventstore-mysql',
options: {
host: 'localhost',
port: 3306,
user: 'customUser',
password: 'customPassword',
database: 'customDatabaseName',
eventsTableName: 'customTableName',
}
},
...
}

eventstore-postgresqlā€‹

Used to store events in a PostgreSQL database.

This adapter supports the following options:

Option NameDescription
databaseThe name of a database.
databaseNameThe name of a PostgreSQL database schema.
eventsTableNameThe name of a database table used to store events.
hostThe database server host name.
passwordThe user's password.
portThe database server port number.
secretsTableNameThe name of a database table used to store secrets.
snapshotBucketSizeThe number of events between aggregate snapshots.
userThe user name used to log in to the database server.
Exampleā€‹
const prodConfig = {
eventstoreAdapter: {
module: '@resolve-js/eventstore-postgresql',
options: {
user: 'user',
password: 'password',
database: 'postgres',
host: 'localhost',
port: 5432,
databaseName: 'public',
eventsTableName: 'events',
}
},
...
}

middlewareā€‹

Specifies middleware for aggregates and read models. The configuration object can contain the following fields:

FieldDescription
aggregateAn array of file paths. Each value in the array specifies a file that exports a middleware function.
readModelAn object that contains read model middleware settings (see below).

The readModel object can have the following fields:

FieldDescription
projectionLists files that contain read model projection middleware.
resolverLists files that contain read model resolver middleware.

Middlewares of all types are invoked in the order that they are listed in the configuration object.

Exampleā€‹

const appConfig = {
...
middlewares: {
aggregate: [
'common/middlewares/command-middleware-1.js',
'common/middlewares/command-middleware-2.js',
'common/middlewares/command-middleware-3.js'
],
readModel: {
projection: ['common/middlewares/projection-middleware.js'],
resolver: ['common/middlewares/resolver-middleware.js']
}
},
...
}

monitoringAdaptersā€‹

Specifies the application's Monitoring adapters as key-value pairs. An adapter configuration object contains the following fields:

FieldDescription
moduleThe name of a module or the path to a file that defines an adapter .
optionsAn object that defines the adapter's options as key-value pairs.

Example:ā€‹

monitoringAdapters: {
default: {
module: '@resolve-js/monitoring-console',
options: {
publishMode: 'processExit',
},
},
}

The following adapters are available:

Module NameDescription
@resolve-js/monitoring-consolePrints metrics to the text console.
@resolve-js/monitoring-aws-cloudwatchPublishes metrics to AWS CloudWatch.

In the cloud environment, if the default adapter is not explicitly specified, it is added automatically. In this case, the '@resolve-js/monitoring-aws-cloudwatch' adapter is used.

@resolve-js/monitoring-consoleā€‹

The @resolve-js/monitoring-console adapter accepts the following option:

Option NameDescription
publishModeSpecifies when to display a summary on the collected metrics in the console.
Available values: all, resolveDispose, processExit. Default: processExit.

@resolve-js/monitoring-aws-cloudwatchā€‹

The @resolve-js/monitoring-aws-cloudwatch adapter accepts the following options:

Option NameDescription
deploymentIdSpecifies the reSolve Cloud deployment ID.
resolveVersionSpecifies the reSolve version.

jwtCookieā€‹

Specifies global settings for the application's JWT cookies. The configuration object contains the following fields:

FieldDescription
nameThe cookie's name.
maxAgeThe value of the cookie's max-age attribute.
jwtCookie: {
name: 'jwt',
maxAge: 31536000000
}

modeā€‹

Specifies webpacks's mode configuration.

Supported values:

  • development
  • production
  • none

nameā€‹

Specifies the application's name.

If this option is omitted, the package name defined in the package.json file is reused as the application's name.

readModelsā€‹

An array of the application's Read Models. A Read Model configuration object within this array contains the following fields:

FieldDescription
nameThe Read Model's name.
projectionA path to a file that defines a Read Model projection.
resolversA path to a file that defines a Read Model resolver.
connectorNameThe name of a connector used to connect the Read Model to its store.

Example:ā€‹

readModels: [
{
name: 'ShoppingLists',
projection: 'common/read-models/shopping_lists.projection.js',
resolvers: 'common/read-models/shopping_lists.resolvers.js',
connectorName: 'default',
},
]

readModelConnectorsā€‹

Specifies the application's Read Model connectors as key-value pairs. A connector configuration object contains the following fields:

FieldDescription
moduleThe name of a module or the path to a file that defines a connector.
optionsAn object that defines the connector's options as key-value pairs.

Example:ā€‹

readModelConnectors: {
default: {
module: '@resolve-js/readmodel-mysql',
options: {
host: 'localhost',
port: 3306,
user: 'root',
password: '',
database: 'ReadModelStoriesSample'
}
}
}

The following connectors are available:

Module NameDescription
@resolve-js/readmodel-liteUsed to store Read Model data in an SQLite database.
@resolve-js/readmodel-mysqlUsed to store Read Model data in a MySQL database.
@resolve-js/readmodel-postgresqlUsed to store Read Model data in a PostgreSQL database.

readmodel-liteā€‹

Used to store Read Model data in an SQLite database.

This connector supports the following option:

Option NameDescription
databaseFileSpecifies the path to a database file used to store Read Model data. If set to ':memory:', all data is stored in memory and is lost when the application is shut down or restarted.
Exampleā€‹
const prodConfig = {
readModelConnectors: {
default: {
module: '@resolve-js/readmodel-lite',
options: {
databaseFile: 'data/read-models.db'
// databaseFile: ':memory:'
},
},
},
...
}

readmodel-mysqlā€‹

Used to store Read Model data in a MySQL database.

To configure the database connection for this adapter, specify MySQL connection setting as the adapter's options.

Exampleā€‹
const prodConfig = {
readModelConnectors: {
default: {
module: '@resolve-js/readmodel-mysql',
options: {
host: 'localhost',
port: 3306,
user: 'customUser',
password: 'customPassword',
database: 'customDatabaseName'
}
}
},
...
}

readmodel-postgresqlā€‹

Used to store Read Model data in a PostgreSQL database.

This connector supports the following options:

Option NameDescription
databaseThe name of a database.
databaseNameThe name of a PostgreSQL database schema.
hostThe database server host name.
passwordThe user's password.
portThe database server port number.
tablePrefixOptional table name prefix.
userThe user name used to log in to the database server.
Exampleā€‹
const prodConfig = {
readModelConnectors: {
default: {
module: '@resolve-js/readmodel-postgresql',
options: {
user: 'user',
password: 'password',
database: 'postgres',
host: 'localhost',
port: 5432,
databaseName: 'public',
}
}
},
...
}

runtimeā€‹

Specifies the runtime that the application targets and the options for this runtime. A runtime configuration object has the following structure:

{
runtime, // A string that specifies the runtime package to use.
options // An object that contains runtime-specific options.
}

ReSolve includes the following runtime packages:

  • "@resolve-js/runtime-single-process" - A runtime that targets a standalone server or local machine.
  • "@resolve-js/runtime-aws-serverless" - A runtime that targets the AWS serverless environment.

Optionsā€‹

The options configuration object has the following structure:

{
importMode, // Specifies whether to use *static* or *dynamic* imports between the application's modules.
host, // (single-process only) Specifies the network host on which to listen for connections. Defaults to `'0.0.0.0'`.
port, // (single-process only) Specifies the server application's port.
emulateWorkerLifetimeLimit, // (single-process only) Used for framework testing. If assigned a numeric value, emulates an AWS Lambda worker's lifetime on a local machine.
}
Example:ā€‹
// config.prod.js
const prodConfig = {
runtime: {
module: '@resolve-js/runtime-single-process',
options: {
host: declareRuntimeEnv('HOST', 'localhost'),
port: declareRuntimeEnv('PORT', '3000'),
},
},
...
}

sagasā€‹

Specifies an array of the application's Sagas. A Saga configuration object within this array contains the following fields:

FieldDescription
sourceA path to a file that defines the Saga's handlers or both handlers and side effects.
sideEffectsA path to a file that defines the Saga's side effects.
connectorNameDefines a Read Model storage used to store the saga's persistent data.
encryptionA path to a file that defines data encryption and decryption logic.

Example:ā€‹

const appConfig = {
sagas: [
{
name: 'UserConfirmation',
source: 'saga.js',
connectorName: 'default',
},
],
}

schedulersā€‹

Specifies saga schedulers as key-value pairs. A scheduler configuration object contains the following fields:

FieldDescription
adapterThe scheduler adapter settings.
connectorNameThe name of the readModel connector used by this scheduler.

A scheduler adapter configuration object has the following fields:

FieldDescription
moduleThe name of a module or the path to a file that defines an adapter.
optionsAn object that defines the adapter's options as key-value pairs.

Example:ā€‹

schedulers: {
scheduler: {
adapter: {
module: 'resolve-scheduler-local',
options: {}
},
connectorName: 'default'
}
},

serverImportsā€‹

Same as clientImports but affects the client script invoked on the server by the Server Side Rendering (SSR) script.

staticDirā€‹

Specifies the project directory that contains static files.

staticPathā€‹

Specifies the URL path to static files.

viewModelsā€‹

Specifies an array of the application's View Models. A View Model configuration object within this array contains the following fields:

FieldDescription
nameThe View Model's name.
projectionA path to a file that defines a View Model projection.
resolverA path to a file that defines a View Model resolver.
serializeStateA path to a file that defines a state serializer function.
deserializeStateA path to a file that defines a state deserializer function.
encryptionA path to a file that defines data encryption and decryption logic.
viewModels: [
{
name: 'shoppingList',
projection: 'common/view-models/shopping_list.projection.js',
},
]