@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.
- package/package.json +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.
|
|
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
|
+
}
|
package/src/application.js
CHANGED
|
@@ -10,36 +10,32 @@ let UserService = require('./services/user_manager/service')
|
|
|
10
10
|
let defaultServiceRoot = __dirname + '/services';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
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 = {
|
|
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: {
|
|
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: {
|
|
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.
|
|
135
|
-
userDatabaseDetail.concat(options.
|
|
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({
|
|
175
|
+
done({
|
|
176
|
+
app,
|
|
177
|
+
server
|
|
178
|
+
});
|
|
172
179
|
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
module.exports = createRest;
|
|
180
|
+
}
|