Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

...

The below shows the difference between the config file of a service written without the composer, and the index file of a service written with the composer.

Config.js

...

Code Block
languagejs
titleStandard Config.js
linenumberstrue
module.exports = {
	type: 'service',
	prerequisites: {
		cpu: '',
		memory: ''
	},
	serviceVersion: 1,
	serviceName: "shoppingCart",
	serviceGroup: "My Commerce Project",
	requestTimeout: 30,
	requestTimeoutRenewal: 5,
	servicePort: 4021,
	extKeyRequired: false,
	session: true,
	errors: {
		400: "Failed to connect to Database!",
		401: "Invalid User Id Provided",
		402: "Error fetching Entries!",
		407: "Error Loading Model!"
	},
	schema: {
		"commonFields": {
			"userId": {
				"source": ['query.userId'],
				"required": true,
				"validation": {
					"type": "string"
				}
			}
		},

		"/getCart": {
			"_apiInfo": {
				"l": "Get Cart"
			},
			"commonFields": ["userId"]
		},
		"/setCart": {
			"_apiInfo": {
				"l" : "Set Cart"
			},
			"commonFields": ["userId"],
			"items": {
				"source": ['body.items'],
				"required": true,
				"validation": {
					"type": "array",
					"items": {
						//.....
					}
				}
			}
		},
		"/emptyCart": {
			"_apiInfo": {
				"l" : "Empty Cart"
			},
			"commonFields": ["userId"]
		}
	}
};
Code Block
languagejs
titleConfig.js Used by Composer
linenumberstrue
module.exports = {
	type: 'service',
	prerequisites: {
		cpu: '',
		memory: ''
	},
	serviceVersion: 1,
	serviceName: "shoppingCart",
	serviceGroup: "My Commerce Project",
	requestTimeout: 30,
	requestTimeoutRenewal: 5,
	servicePort: 4021,
	extKeyRequired: false,
	session: true,
	errors: {
		400: "Failed to connect to Database!",
		401: "Invalid User Id Provided",
		402: "Error fetching Entries!",
		407: "Error Loading Model!"
	},
	schema: {
		"commonFields": {
			"userId": {
				"source": ['query.userId'],
				"required": true,
				"validation": {
					"type": "string"
				}
			}
		},

		"/getCart": {
			"_apiInfo": {
				"l": "Get Cart"
			},
			"mw": __dirname + "/lib/mw/getCart.js",
			"imfv": {
				"commonFields": ["userId"]
			}
		},
		"/setCart": {
			"_apiInfo": {
				"l" : "Set Cart"
			},
			"mw": __dirname + "/lib/mw/setCart.js",
			"imfv": {
				"commonFields": ["userId"],
				"custom": {
					"items": {
						"source": ['body.items'],
						"required": true,
						"validation": {
							"type": "array",
							"items": {
								//.....
							}
						}
					}
				}
			}
		},
		"/emptyCart": {
			"_apiInfo": {
				"l" : "Empty Cart"
			},
			"mw": __dirname + "/lib/mw/emptyCart.js",
			"imfv": {
				"commonFields": ["userId"]
			}
		}
	},
	dbs: [
		{
			prefix: "test_",
			name: "myDatabase",
			model: "mongo",
			multitenant: false
		}
	]
};

As you can see the change is very minimal.

...

The table below explains the properties of this new entry.

Property NameProperty TypeMandatoryDefault ValueDescription
prefixstringNON/A

optional database prefix to use.
ex: test_ → test_myDatabase

namestringYESN/Athe name of the database that this service will use
modelstringYESN/Athe name of the model to use
multitenantbooleanNON/Aif the database is multitenant or not.
Note

Both the database name and the multitenant properties should be replicated in the Registry where the service will be deployed. You can create/configure the registry by using the Dashboard UI under the Deploy Pillar.