@modular-rest/server 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/application.js +31 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-rest/server",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "a nodejs module based on KOAJS for developing Rest-APIs in a modular solution.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -10,27 +10,30 @@ let UserService = require('./services/user_manager/service')
10
10
  let defaultServiceRoot = __dirname + '/services';
11
11
 
12
12
  /**
13
- * @param {object} options
14
- * @param {object} options.cors Options for koa-cors middleware
15
- * @param {string} options.componentDirectory Root directory of your router.js/db.js files.
16
- * @param {string} options.uploadDirectory Root directory for uploaded files.
17
- * @param {function} options.onBeforeInit A callback called before initializing the Koa server.
18
- * @param {function} options.onAfterInit A callback called after server initialization.
19
- * @param {number} options.port Server port.
20
- * @param {boolean} options.dontListen If true, the server will not run and will only return the Koa app object.
21
- * @param {string} options.mongo MongoDB options.
22
- * @param {string} options.mongo.dbPrefix A prefix for your database name.
23
- * @param {string} options.mongo.mongoBaseAddress The address of your MongoDB server without any database specification.
24
- * @param {string} options.mongo.addressMap Specific addresses for each database.
25
- * @param {object} options.keypair RSA keypair for the authentication module.
26
- * @param {string} options.keypair.private Private key.
27
- * @param {string} options.keypair.public Public key.
28
- * @param {object} options.adminUser Super admin user to be created as the first user of the system.
29
- * @param {string} options.adminUser.email Admin user email.
30
- * @param {string} options.adminUser.password Admin user password.
31
- * @param {function} options.verificationCodeGeneratorMethod A method to return a verification code when someone wants to register a new user.
32
- * @param {array} options.CollectionDefinitions An array of additional collection definitions.
33
- * @returns {Promise<{app: Koa, server: http.Server}>} Returns a promise that resolves to an object containing the Koa app object and the server object.
13
+ * @param {{
14
+ * cors: any; // Options for @koa/cors middleware.
15
+ * modulesPath: string; // Root directory of your router.js/db.js files.
16
+ * staticPath: string; // Root directory for uploaded files.
17
+ * onBeforeInit: (koaApp) => void; // A callback called before initializing the Koa server.
18
+ * onAfterInit: (koaApp) => void; // A callback called after server initialization.
19
+ * port: number; // Server port.
20
+ * dontListen: boolean; // If true, the server will not run and will only return the Koa app object.
21
+ * mongo: {
22
+ * dbPrefix: string; // A prefix for your database name.
23
+ * mongoBaseAddress: string; // The address of your MongoDB server without any database specification.
24
+ * addressMap: string; // Specific addresses for each database.
25
+ * };
26
+ * keypair: {
27
+ * private: string; // Private key for RSA authentication.
28
+ * public: string; // Public key for RSA authentication.
29
+ * };
30
+ * adminUser: {
31
+ * email: string; // Admin user email.
32
+ * password: string; // Admin user password.
33
+ * };
34
+ * verificationCodeGeneratorMethod: () => string; // A method to return a verification code when registering a new user.
35
+ * collectionDefinitions: CollectionDefinition[]; // An array of additional collection definitions.
36
+ * }} options
34
37
  */
35
38
  module.exports = async function createRest(options) {
36
39
 
@@ -68,9 +71,9 @@ module.exports = async function createRest(options) {
68
71
  /**
69
72
  * Plug In KoaStatic
70
73
  */
71
- if (options.uploadDirectory)
74
+ if (options.staticPath)
72
75
  app.use(koaStatic({
73
- rootDir: options.uploadDirectory,
76
+ rootDir: options.staticPath,
74
77
  rootPath: '/assets/',
75
78
 
76
79
  }));
@@ -115,15 +118,15 @@ module.exports = async function createRest(options) {
115
118
  *
116
119
  * Plug in routes and database
117
120
  */
118
- if (options.componentDirectory) {
121
+ if (options.modulesPath) {
119
122
 
120
123
  // Plug in user routes
121
- await Combination.combineRoutesByFilePath(options.componentDirectory, app);
124
+ await Combination.combineRoutesByFilePath(options.modulesPath, app);
122
125
 
123
126
  // Collect user CollectionDefinitions (db.js files)
124
127
  let userDatabaseDetail = [];
125
128
  userDatabaseDetail = await Combination.combineModulesByFilePath({
126
- rootDirectory: options.componentDirectory,
129
+ rootDirectory: options.modulesPath,
127
130
  filename: {
128
131
  name: 'db',
129
132
  extension: '.js'
@@ -132,8 +135,8 @@ module.exports = async function createRest(options) {
132
135
  });
133
136
 
134
137
  // combine additional CollectionDefinitions
135
- if (options.CollectionDefinitions) {
136
- userDatabaseDetail.concat(options.CollectionDefinitions)
138
+ if (options.collectionDefinitions) {
139
+ userDatabaseDetail.concat(options.collectionDefinitions)
137
140
  }
138
141
 
139
142
  // Plug in user CollectionDefinitions