@modular-rest/server 1.3.1 → 1.3.2
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 +39 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modular-rest/server",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
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,29 @@ let UserService = require('./services/user_manager/service')
|
|
|
10
10
|
let defaultServiceRoot = __dirname + '/services';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
13
|
* @param {object} options
|
|
15
|
-
*
|
|
16
|
-
* @param {
|
|
17
|
-
*
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {
|
|
23
|
-
* @param {
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @param {
|
|
27
|
-
* @param {string} options.
|
|
28
|
-
* @param {string} options.
|
|
29
|
-
* @param {
|
|
30
|
-
*
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {
|
|
33
|
-
* @param {
|
|
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
|
|
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.
|
|
41
34
|
*/
|
|
42
|
-
async function createRest(options) {
|
|
35
|
+
module.exports = async function createRest(options) {
|
|
43
36
|
|
|
44
37
|
options = {
|
|
45
38
|
port: 3000,
|
|
@@ -67,7 +60,9 @@ async function createRest(options) {
|
|
|
67
60
|
/**
|
|
68
61
|
* Plug in BodyParser
|
|
69
62
|
*/
|
|
70
|
-
let bodyParserOptions = {
|
|
63
|
+
let bodyParserOptions = {
|
|
64
|
+
multipart: true
|
|
65
|
+
};
|
|
71
66
|
app.use(koaBody(bodyParserOptions));
|
|
72
67
|
|
|
73
68
|
/**
|
|
@@ -75,8 +70,8 @@ async function createRest(options) {
|
|
|
75
70
|
*/
|
|
76
71
|
if (options.uploadDirectory)
|
|
77
72
|
app.use(koaStatic({
|
|
78
|
-
rootDir: options.uploadDirectory,
|
|
79
|
-
rootPath: '/assets/',
|
|
73
|
+
rootDir: options.uploadDirectory,
|
|
74
|
+
rootPath: '/assets/',
|
|
80
75
|
|
|
81
76
|
}));
|
|
82
77
|
|
|
@@ -99,7 +94,10 @@ async function createRest(options) {
|
|
|
99
94
|
// Collect default databaseDefinitions
|
|
100
95
|
let defaultDatabaseDefinitionList = await Combination.combineModulesByFilePath({
|
|
101
96
|
rootDirectory: defaultServiceRoot,
|
|
102
|
-
filename: {
|
|
97
|
+
filename: {
|
|
98
|
+
name: 'db',
|
|
99
|
+
extension: '.js'
|
|
100
|
+
},
|
|
103
101
|
combineWithRoot: true
|
|
104
102
|
});
|
|
105
103
|
|
|
@@ -126,7 +124,10 @@ async function createRest(options) {
|
|
|
126
124
|
let userDatabaseDetail = [];
|
|
127
125
|
userDatabaseDetail = await Combination.combineModulesByFilePath({
|
|
128
126
|
rootDirectory: options.componentDirectory,
|
|
129
|
-
filename: {
|
|
127
|
+
filename: {
|
|
128
|
+
name: 'db',
|
|
129
|
+
extension: '.js'
|
|
130
|
+
},
|
|
130
131
|
combineWithRoot: true
|
|
131
132
|
});
|
|
132
133
|
|
|
@@ -168,8 +169,9 @@ async function createRest(options) {
|
|
|
168
169
|
if (options.onAfterInit) options.onAfterInit(app);
|
|
169
170
|
|
|
170
171
|
//done
|
|
171
|
-
done({
|
|
172
|
+
done({
|
|
173
|
+
app,
|
|
174
|
+
server
|
|
175
|
+
});
|
|
172
176
|
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
module.exports = createRest;
|
|
177
|
+
}
|