Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Introduction



Config.js


Standard Config.js
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"]
		}
	}
};
Config.js Used by Composer
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 composer asks you provided it with a new configuration entry dbs so that it knows what models and databases it should initialized and give them to you.

The composer also asks you provide one middleware file per API and it will load it for you at run-time when this API is invoked and in that middleware you write the business logic of that API.

Finally the composer asks you to add imfv in each API and inside it put the inputs configuration instead of using the standard SOAJS way.


Databases


The config.js that is passed to the composer contains a new entry called dbs.This entry is not required if you were to build a normal SOAJS microservice or daemon.

The dbs entry stands for databases and disposes of a list of databases that the service you want to launch will use.

In Addition, each database entry is associate with a model where the the driver needed for NodeJs to communicate with this database exists.

The composer will Initialize and load it and give it you so you can use it in the middleware files.


The table below explains the properties of this new entry.

Property NameProperty TypeMandatoryDefault ValueDescription




















  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.