@mimik/init
v6.1.1
Published
Init process for micro-service
Readme
init
Example
import init from '@mimik/init';
init(app, rootDir, config, [dbValidate], cluster, { postOps: [subscribe] }).then(({ config: c }) => config = c);init~init(app, rootDir, config, validates, cluster, options) ⇒ Promise.<object>
Init process for a micro-service.
Kind: inner method of init
Returns: Promise.<object> - The updated configuration.
The options parameter has the following structure:
{
preOps: [function], // functions to process before starting the micro-service
postOps: [function], // functions to process after starting the micro-service
exitOps: [function], // functions to process before exiting the micro-service
secOptions: { securityDefinition: function }, // extra security options to validate the API request
extractName: string, // ability to extract data from the req and send it to a logging environment
metrics: object, // to generate information for `/metrics`
oidcOps: function, // OIDC operations to be called during init
formats: object, // custom formats for API validation
}The return object has the following structure:
{
config: The configuration object,
}For the preOps, postOps and exitOps the functions are executed with 3 parameters (correlationId, config, server).
When config.registration.afterPostOpsSet is 'on', postOps run before cluster registration; otherwise registration happens first.
The following routes are reserved: /healthcheck and /metrics.
The base path is defined by taking the URL property of the first item of the servers array in the API definition file. Only relative URL addresses will be handled (e.g. /mss/v1) and templates in the URL are not allowed.
| Param | Type | Description |
| --- | --- | --- |
| app | object | The app implementing the micro-service. |
| rootDir | string | The root directory of the micro-service. |
| config | object | Configuration of the micro-service. |
| validates | array | Array of Promises to validate dependent systems (database, topic). |
| cluster | object | Object with register and unRegister methods for cluster management. |
| options | object | Options to start the micro-service. Can be null. |
