@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.
- package/package.json +1 -1
- package/src/application.js +31 -28
package/package.json
CHANGED
package/src/application.js
CHANGED
|
@@ -10,27 +10,30 @@ let UserService = require('./services/user_manager/service')
|
|
|
10
10
|
let defaultServiceRoot = __dirname + '/services';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @param {
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
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.
|
|
74
|
+
if (options.staticPath)
|
|
72
75
|
app.use(koaStatic({
|
|
73
|
-
rootDir: options.
|
|
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.
|
|
121
|
+
if (options.modulesPath) {
|
|
119
122
|
|
|
120
123
|
// Plug in user routes
|
|
121
|
-
await Combination.combineRoutesByFilePath(options.
|
|
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.
|
|
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.
|
|
136
|
-
userDatabaseDetail.concat(options.
|
|
138
|
+
if (options.collectionDefinitions) {
|
|
139
|
+
userDatabaseDetail.concat(options.collectionDefinitions)
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
// Plug in user CollectionDefinitions
|