@modular-rest/server 1.3.1 → 1.3.3

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 +2 -2
  2. package/src/application.js +45 -40
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-rest/server",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
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": {
@@ -36,4 +36,4 @@
36
36
  "nested-property": "^4.0.0"
37
37
  },
38
38
  "devDependencies": {}
39
- }
39
+ }
@@ -10,36 +10,32 @@ let UserService = require('./services/user_manager/service')
10
10
  let defaultServiceRoot = __dirname + '/services';
11
11
 
12
12
  /**
13
- *
14
- * @param {object} options
15
- *
16
- * @param {object} options.cors @koa/cors options
17
- *
18
- * @param {string} options.componentDirectory root directory of your router.js/db.js files.
19
- * @param {string} options.uploadDirectory root directory for upload files.
20
- * @param {function} options.onBeforeInit a callback being called before init koa server.
21
- * @param {function} options.onAfterInit a callback being called after server initialization.
22
- * @param {number} options.port server port
23
- * @param {boolean} options.dontListen server will not being run if it was true and just return koa app object.
24
- *
25
- *
26
- * @param {string} options.mongo mongodb options.
27
- * @param {string} options.mongo.dbPrefix a prefix for your database name.
28
- * @param {string} options.mongo.mongoBaseAddress the address of your mongo server without any database specification on it.
29
- * @param {string} options.mongo.addressMap specific address for each database
30
- *
31
- * @param {object} options.keypair RSA keypair for authentication module
32
- * @param {string} options.keypair.private
33
- * @param {string} options.keypair.public
34
- *
35
- * @param {object} options.adminUser supper admin user to being created as the first user of the system.
36
- * @param {string} options.adminUser.email
37
- * @param {string} options.adminUser.password
38
- *
39
- * @param {function} options.verificationCodeGeneratorMethod a method to return a code as verification when someone want to register a new user.
40
- * @param {array} options.CollectionDefinitions an array of additional collectionDefinitions
13
+ * @param {{
14
+ * cors: any; // Options for @koa/cors middleware.
15
+ * componentDirectory: string; // Root directory of your router.js/db.js files.
16
+ * uploadDirectory: 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
41
37
  */
42
- async function createRest(options) {
38
+ module.exports = async function createRest(options) {
43
39
 
44
40
  options = {
45
41
  port: 3000,
@@ -67,7 +63,9 @@ async function createRest(options) {
67
63
  /**
68
64
  * Plug in BodyParser
69
65
  */
70
- let bodyParserOptions = { multipart: true };
66
+ let bodyParserOptions = {
67
+ multipart: true
68
+ };
71
69
  app.use(koaBody(bodyParserOptions));
72
70
 
73
71
  /**
@@ -75,8 +73,8 @@ async function createRest(options) {
75
73
  */
76
74
  if (options.uploadDirectory)
77
75
  app.use(koaStatic({
78
- rootDir: options.uploadDirectory,
79
- rootPath: '/assets/',
76
+ rootDir: options.uploadDirectory,
77
+ rootPath: '/assets/',
80
78
 
81
79
  }));
82
80
 
@@ -99,7 +97,10 @@ async function createRest(options) {
99
97
  // Collect default databaseDefinitions
100
98
  let defaultDatabaseDefinitionList = await Combination.combineModulesByFilePath({
101
99
  rootDirectory: defaultServiceRoot,
102
- filename: { name: 'db', extension: '.js' },
100
+ filename: {
101
+ name: 'db',
102
+ extension: '.js'
103
+ },
103
104
  combineWithRoot: true
104
105
  });
105
106
 
@@ -126,13 +127,16 @@ async function createRest(options) {
126
127
  let userDatabaseDetail = [];
127
128
  userDatabaseDetail = await Combination.combineModulesByFilePath({
128
129
  rootDirectory: options.componentDirectory,
129
- filename: { name: 'db', extension: '.js' },
130
+ filename: {
131
+ name: 'db',
132
+ extension: '.js'
133
+ },
130
134
  combineWithRoot: true
131
135
  });
132
136
 
133
137
  // combine additional CollectionDefinitions
134
- if (options.CollectionDefinitions) {
135
- userDatabaseDetail.concat(options.CollectionDefinitions)
138
+ if (options.collectionDefinitions) {
139
+ userDatabaseDetail.concat(options.collectionDefinitions)
136
140
  }
137
141
 
138
142
  // Plug in user CollectionDefinitions
@@ -168,8 +172,9 @@ async function createRest(options) {
168
172
  if (options.onAfterInit) options.onAfterInit(app);
169
173
 
170
174
  //done
171
- done({ app, server });
175
+ done({
176
+ app,
177
+ server
178
+ });
172
179
  });
173
- }
174
-
175
- module.exports = createRest;
180
+ }