beech-api 3.5.7 → 3.7.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/README.md +401 -186
- package/index.js +2 -3
- package/package.json +15 -8
- package/packages/cli/beech +2 -2
- package/packages/cli/bin/{beech.js → beech-app.js} +105 -43
- package/packages/cli/bin/beech-service.js +133 -0
- package/packages/cli/core/auth/Credentials.js +76 -35
- package/packages/cli/core/auth/Passport.js +318 -184
- package/packages/cli/core/auth/_Request.js +12 -0
- package/packages/cli/core/configure/_gitignore +9 -1
- package/packages/cli/core/configure/app.config-basic.js +10 -10
- package/packages/cli/core/configure/app.config-sequelize.js +17 -12
- package/packages/cli/core/configure/beech.config.js +8 -0
- package/packages/cli/core/configure/global.config-basic.js +4 -4
- package/packages/cli/core/configure/global.config-sequelize.js +4 -4
- package/packages/cli/core/configure/passport.config.js +5 -15
- package/packages/cli/core/databases/mysql.js +53 -29
- package/packages/cli/core/databases/sequelize.js +135 -105
- package/packages/cli/core/databases/test.js +168 -0
- package/packages/cli/core/file-walk/file-walk.js +31 -14
- package/packages/cli/core/generator/_add-on +15 -2
- package/packages/cli/core/generator/_endpoints +15 -82
- package/packages/cli/core/generator/_endpoints_basic +39 -0
- package/packages/cli/core/generator/_help +12 -11
- package/packages/cli/core/generator/_help_create +11 -0
- package/packages/cli/core/generator/_help_service +11 -0
- package/packages/cli/core/generator/_models +20 -15
- package/packages/cli/core/generator/{_basic-models → _models_basic} +0 -2
- package/packages/cli/core/generator/_package +5 -4
- package/packages/cli/core/generator/index.js +302 -95
- package/packages/cli/core/helpers/math.js +55 -0
- package/packages/cli/core/helpers/poolEntity.js +31 -0
- package/packages/cli/core/index.js +97 -28
- package/packages/cli/core/origin/index.js +2 -0
- package/packages/cli/core/origin/whitelist/cors.js +91 -0
- package/packages/cli/core/services/http.express.js +338 -201
- package/packages/cli/core/test/utils.js +5 -5
- package/packages/lib/index.js +4 -0
- package/packages/lib/src/endpoint.js +98 -0
- package/packages/lib/src/salt.js +3 -0
- package/packages/lib/src/schema.js +62 -0
- package/packages/lib/src/user.js +196 -0
- package/packages/package.json +4 -6
- package/packages/public/icon/beech_128.png +0 -0
- package/packages/cli/core/generator/_create +0 -7
- package/packages/lib/beech.js +0 -136
- package/packages/lib/salt.js +0 -3
- /package/packages/cli/core/generator/{_basic-helpers → _helpers_basic} +0 -0
package/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
const { Base, Schema, Store, Update } = require("./packages/lib/index");
|
|
2
|
+
module.exports = { Base, Schema, Store, Update };
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beech-api",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Command line interface for rapid Beech API development",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"api",
|
|
7
|
+
"node-api",
|
|
8
|
+
"api-framework",
|
|
6
9
|
"beech-api",
|
|
7
10
|
"cli",
|
|
8
|
-
"
|
|
9
|
-
"nodejs",
|
|
10
|
-
"api-framework"
|
|
11
|
+
"nodejs"
|
|
11
12
|
],
|
|
12
13
|
"license": "MIT",
|
|
13
14
|
"repository": {
|
|
@@ -17,7 +18,8 @@
|
|
|
17
18
|
},
|
|
18
19
|
"authors": "bombkiml",
|
|
19
20
|
"bin": {
|
|
20
|
-
"beech-app": "./packages/cli/bin/beech.js",
|
|
21
|
+
"beech-app": "./packages/cli/bin/beech-app.js",
|
|
22
|
+
"beech-service": "./packages/cli/bin/beech-service.js",
|
|
21
23
|
"beech": "./packages/cli/core/generator/index.js"
|
|
22
24
|
},
|
|
23
25
|
"bugs": {
|
|
@@ -26,15 +28,17 @@
|
|
|
26
28
|
"homepage": "https://github.com/bombkiml/beech-api/blob/master/README.md",
|
|
27
29
|
"deprecated": false,
|
|
28
30
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
31
|
+
"node": ">=14.19"
|
|
30
32
|
},
|
|
31
33
|
"dependencies": {
|
|
32
34
|
"app-root-path": "^3.0.0",
|
|
33
35
|
"axios": "^0.26.1",
|
|
36
|
+
"child-process-promise": "^2.2.1",
|
|
34
37
|
"cli-clear": "^1.0.4",
|
|
35
38
|
"cookie-parser": "1.4.3",
|
|
36
39
|
"cors": "^2.8.1",
|
|
37
|
-
"
|
|
40
|
+
"cryptr": "^6.3.0",
|
|
41
|
+
"express": "4.19.2",
|
|
38
42
|
"express-session": "^1.17.1",
|
|
39
43
|
"express-validator": "2.21.0",
|
|
40
44
|
"fs": "0.0.1-security",
|
|
@@ -42,11 +46,13 @@
|
|
|
42
46
|
"jsonwebtoken": "^8.5.1",
|
|
43
47
|
"log-update": "^4.0.0",
|
|
44
48
|
"md5": "^2.3.0",
|
|
49
|
+
"method-override": "^3.0.0",
|
|
45
50
|
"mkdirp": "^2.1.6",
|
|
46
51
|
"module-alias": "^2.2.2",
|
|
47
52
|
"mysql": "^2.18.1",
|
|
48
53
|
"mysql2": "^2.3.3",
|
|
49
|
-
"node-
|
|
54
|
+
"node-emoji": "^1.11.0",
|
|
55
|
+
"node-notifier": "^10.0.1",
|
|
50
56
|
"passport": "^0.6.0",
|
|
51
57
|
"passport-facebook": "^3.0.0",
|
|
52
58
|
"passport-google-oauth": "^2.0.0",
|
|
@@ -59,6 +65,7 @@
|
|
|
59
65
|
},
|
|
60
66
|
"devDependencies": {
|
|
61
67
|
"jest": "^28.1.3",
|
|
68
|
+
"nodemon": "^3.1.0",
|
|
62
69
|
"sequelize-cli": "^5.5.1"
|
|
63
70
|
},
|
|
64
71
|
"jest": {
|
package/packages/cli/beech
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* The beech api (cli) package generator and server (bash for developer and production build)
|
|
5
5
|
*
|
|
6
6
|
* @author bombkiml
|
|
7
|
-
* @version 3.
|
|
8
|
-
* @built Apr
|
|
7
|
+
* @version 3.7
|
|
8
|
+
* @built Apr 19, 2024 at 16:20:09
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
11
|
(process.argv[2]) ? require('./core/generator/index') : require('./core/index')
|
|
@@ -41,6 +41,8 @@ class Beech {
|
|
|
41
41
|
let pasteGloablConfigFile = this.argument + '/global.config.js';
|
|
42
42
|
let tmpGitignoreFile = __dirname + '/../core/configure/_gitignore';
|
|
43
43
|
let pasteGitignoreFile = this.argument + '/.gitignore';
|
|
44
|
+
let tmpBeechConfigFile = __dirname + '/../core/configure/beech.config.js';
|
|
45
|
+
let pasteBeechConfigFile = this.argument + '/beech.config.js';
|
|
44
46
|
// start log clear screen
|
|
45
47
|
clear();
|
|
46
48
|
logUpdate("[94mBeech CLI v" + require(__dirname + "/../../../package.json").version);
|
|
@@ -63,22 +65,27 @@ class Beech {
|
|
|
63
65
|
message: "[93mCheck the features needed for your project:[0m",
|
|
64
66
|
choices: [ "Add-Ons", "Basic Helper", "Passport / JWT / Official Strategy Google, Facebook" ],
|
|
65
67
|
} ]).then(resFreat => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
logUpdate(": Initialize...");
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
// init project
|
|
71
|
+
this.makeFolder(this.argument)
|
|
72
|
+
.then(this.copy.bind(this, tmpPackageFile, pastePackageFile))
|
|
73
|
+
//.then(this.contentReplace.bind(this, pastePackageFile, { 'application': this.argument }))
|
|
74
|
+
.then(this.copy.bind(this, tmpConfigFile, pasteConfigFile))
|
|
75
|
+
.then(this.copy.bind(this, tmpJestFile, pasteJestFile))
|
|
76
|
+
.then(this.copy.bind(this, tmpJsConfigFile, pasteJsConfigFile))
|
|
77
|
+
.then(this.copy.bind(this, tmpDotSequelizercFile, pasteDotSequelizercFile))
|
|
78
|
+
.then(this.copy.bind(this, tmpGloablConfigFile, pasteGloablConfigFile))
|
|
79
|
+
.then(this.copy.bind(this, tmpGitignoreFile, pasteGitignoreFile))
|
|
80
|
+
.then(this.copy.bind(this, tmpBeechConfigFile, pasteBeechConfigFile))
|
|
81
|
+
.then(this.contentReplace.bind(this, pastePackageFile, { 'application': this.argument }))
|
|
82
|
+
.then(this.generateKeyConfigFile.bind(this, this.argument))
|
|
83
|
+
.then(this.installPackage.bind(this, this.argument, resFreat.freature))
|
|
84
|
+
.then(console.log("\n[104m [37mProcessing [0m [0m The Application `" + this.argument + "` is creating...\n"))
|
|
85
|
+
.catch((err) => {
|
|
86
|
+
throw err;
|
|
87
|
+
});
|
|
88
|
+
}, 2000);
|
|
82
89
|
});
|
|
83
90
|
});
|
|
84
91
|
} else {
|
|
@@ -87,11 +94,62 @@ class Beech {
|
|
|
87
94
|
} else {
|
|
88
95
|
resolve("\n[103m[90m Warning [0m[0m Please specify your project name.");
|
|
89
96
|
}
|
|
97
|
+
} else if (this.option == "update") {
|
|
98
|
+
// upgrade the beech-api package
|
|
99
|
+
let isGlobalYarn = "yarn add beech-api";
|
|
100
|
+
let isGlobalNpm = "npm update beech-api";
|
|
101
|
+
let processUpdate = null;
|
|
102
|
+
let lineStdout = "";
|
|
103
|
+
if (this.argument == '-g' || this.argument == '--global') {
|
|
104
|
+
isGlobalNpm = "npm update beech-api -g";
|
|
105
|
+
isGlobalYarn = "yarn global add beech-api";
|
|
106
|
+
}
|
|
107
|
+
// prompt select
|
|
108
|
+
inquirer.prompt([ {
|
|
109
|
+
type: "list",
|
|
110
|
+
name: "package",
|
|
111
|
+
message: "[93mPlease pick a package control:[0m",
|
|
112
|
+
choices: [ "NPM", "Yarn" ],
|
|
113
|
+
} ]).then(selectedPackage => {
|
|
114
|
+
logUpdate(": Initialize...");
|
|
115
|
+
// delay for update package
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
if(selectedPackage.package == "NPM") {
|
|
118
|
+
processUpdate = this.cmd.get(isGlobalNpm, (err) => {
|
|
119
|
+
if (err) { throw err }
|
|
120
|
+
});
|
|
121
|
+
// npm install line shoutout
|
|
122
|
+
processUpdate.stdout.on('data', (npmData) => {
|
|
123
|
+
lineStdout += npmData;
|
|
124
|
+
if (lineStdout[ lineStdout.length - 1 ] == '\n') {
|
|
125
|
+
logUpdate('\n' + lineStdout);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
} else if(selectedPackage.package == "Yarn") {
|
|
129
|
+
processUpdate = this.cmd.get(isGlobalYarn, (err) => {
|
|
130
|
+
if (err) { throw err }
|
|
131
|
+
});
|
|
132
|
+
// yarn install line shoutout
|
|
133
|
+
processUpdate.stdout.on('data', (yarnData) => {
|
|
134
|
+
lineStdout += yarnData;
|
|
135
|
+
if (lineStdout[ lineStdout.length - 1 ] == '\n') {
|
|
136
|
+
logUpdate('\n' + lineStdout);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
logUpdate("\n[101m Faltal [0m Catch update package. Try again...");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}, 1000);
|
|
144
|
+
});
|
|
90
145
|
} else {
|
|
91
|
-
|
|
146
|
+
// help for see avaliable command
|
|
147
|
+
this.help()
|
|
148
|
+
.then(help => resolve(help))
|
|
149
|
+
.catch(err => reject(err));
|
|
92
150
|
}
|
|
93
151
|
} catch (error) {
|
|
94
|
-
|
|
152
|
+
throw error;
|
|
95
153
|
}
|
|
96
154
|
});
|
|
97
155
|
}
|
|
@@ -138,26 +196,30 @@ class Beech {
|
|
|
138
196
|
return new Promise((resolve, reject) => {
|
|
139
197
|
try {
|
|
140
198
|
let helperPath = argument + '/src/helpers/';
|
|
141
|
-
let tmpBasicHelperFile = __dirname + '/../core/generator/
|
|
199
|
+
let tmpBasicHelperFile = __dirname + '/../core/generator/_helpers_basic';
|
|
142
200
|
let pasteBasicHelperFile = helperPath + '/Basic.js';
|
|
143
201
|
let freatureLength = freatureArr.length;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
202
|
+
if (freatureLength) {
|
|
203
|
+
freatureArr.map((f, key) => {
|
|
204
|
+
if (f.split(' ')[ 0 ] == "Add-Ons") {
|
|
205
|
+
(process.env.NODE_ENV == "development") ? this.cmd.get('cd ' + argument + ' && node cli/bin/beech-app.js add-on init') : this.cmd.get('cd ' + argument + ' && beech add-on init');
|
|
206
|
+
console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Add-Ons");
|
|
207
|
+
}
|
|
208
|
+
if (f.split(' ')[ 0 ] == "Basic") {
|
|
209
|
+
this.makeFolder(helperPath).then(this.copy.bind(this, tmpBasicHelperFile, pasteBasicHelperFile))
|
|
210
|
+
console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Basic helper");
|
|
211
|
+
}
|
|
212
|
+
if (f.split(' ')[ 0 ] == "Passport") {
|
|
213
|
+
(process.env.NODE_ENV == "development") ? this.cmd.get('cd ' + argument + ' && node cli/bin/beech-app.js passport init') : this.cmd.get('cd ' + argument + ' && beech passport init');
|
|
214
|
+
console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Passport JWT, Official strategy Google, Facebook");
|
|
215
|
+
}
|
|
216
|
+
if (freatureArr.length == (key + 1)) {
|
|
217
|
+
resolve(true);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
} else {
|
|
221
|
+
resolve(true);
|
|
222
|
+
}
|
|
161
223
|
} catch (error) {
|
|
162
224
|
reject(error);
|
|
163
225
|
}
|
|
@@ -242,7 +304,7 @@ class Beech {
|
|
|
242
304
|
return new Promise((resolve, reject) => {
|
|
243
305
|
try {
|
|
244
306
|
let md5 = require("md5");
|
|
245
|
-
let secret = require(__dirname + "/../../lib/salt").salt;
|
|
307
|
+
let secret = require(__dirname + "/../../lib/src/salt").salt;
|
|
246
308
|
let result = '';
|
|
247
309
|
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
248
310
|
let charactersLength = characters.length;
|
|
@@ -268,17 +330,17 @@ class Beech {
|
|
|
268
330
|
let buf2str = buffer.toString();
|
|
269
331
|
let buf2json = JSON.parse(JSON.stringify(buf2str));
|
|
270
332
|
let buf2eval = eval(buf2json);
|
|
271
|
-
let
|
|
272
|
-
// generate new key
|
|
273
|
-
this.appKeyGenerator(8).then(
|
|
333
|
+
let oldKey = buf2eval.main_config.app_key;
|
|
334
|
+
// generate new key
|
|
335
|
+
this.appKeyGenerator(8).then(newAppKey => {
|
|
274
336
|
// content replace
|
|
275
|
-
let text = data.replace(new RegExp(
|
|
337
|
+
let text = data.replace(new RegExp(oldKey, 'g'), newAppKey);
|
|
276
338
|
// writing the file
|
|
277
339
|
this.fs.writeFile(pjName + "/app.config.js", text, 'utf8', (err) => {
|
|
278
340
|
if (err) {
|
|
279
341
|
throw err;
|
|
280
342
|
} else {
|
|
281
|
-
resolve("\n[102m[90m Passed [0m[0m App
|
|
343
|
+
resolve("\n[102m[90m Passed [0m[0m App key it's new generated.");
|
|
282
344
|
}
|
|
283
345
|
});
|
|
284
346
|
});
|
|
@@ -293,7 +355,7 @@ class Beech {
|
|
|
293
355
|
help() {
|
|
294
356
|
return new Promise((resolve, reject) => {
|
|
295
357
|
try {
|
|
296
|
-
this.fs.readFile(__dirname + "/../core/generator/
|
|
358
|
+
this.fs.readFile(__dirname + "/../core/generator/_help_create", "utf8", (err, data) => {
|
|
297
359
|
if (err) {
|
|
298
360
|
reject(err);
|
|
299
361
|
} else {
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const logUpdate = require("log-update");
|
|
3
|
+
const notifier = require("node-notifier");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const express = require("express");
|
|
6
|
+
const _app_ = express();
|
|
7
|
+
|
|
8
|
+
class Beech {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.embed(process.argv)
|
|
11
|
+
.then(() => this.init()
|
|
12
|
+
.then(status => console.log(status))
|
|
13
|
+
.catch(err => {
|
|
14
|
+
throw err;
|
|
15
|
+
})
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
init() {
|
|
20
|
+
return new Promise(async (resolve, reject) => {
|
|
21
|
+
try {
|
|
22
|
+
if (this.option == "serve") {
|
|
23
|
+
let turnNoti = true;
|
|
24
|
+
if (this.argument == "--silent" || this.argument == "-S") {
|
|
25
|
+
turnNoti = false;
|
|
26
|
+
}
|
|
27
|
+
// check project config file exists ?
|
|
28
|
+
if (this.fs.existsSync(this.configFile)) {
|
|
29
|
+
let testServ = require("http").createServer(_app_);
|
|
30
|
+
testServ.listen(this._config_.main_config.app_port, async () => {
|
|
31
|
+
await testServ.close();
|
|
32
|
+
// Start real service.
|
|
33
|
+
await this.serviceDevStart(this.argument);
|
|
34
|
+
// check turn on nofi
|
|
35
|
+
if (turnNoti) {
|
|
36
|
+
this.notiCompile();
|
|
37
|
+
}
|
|
38
|
+
}).on('error', (err) => {
|
|
39
|
+
console.log("\n[101m Faltal [0m", err);
|
|
40
|
+
})
|
|
41
|
+
} else {
|
|
42
|
+
resolve("\n[101m Faltal [0m The app.conifg.js file is not found.");
|
|
43
|
+
}
|
|
44
|
+
} else if (!this.option || this.option == "-h" || this.option == "?" || this.option == "--help") {
|
|
45
|
+
// help for see avaliable command
|
|
46
|
+
this.help()
|
|
47
|
+
.then(help => resolve(help))
|
|
48
|
+
.catch(err => reject(err));
|
|
49
|
+
} else if (this.option == "build") {
|
|
50
|
+
resolve("\n[101m Notic. [0m The commnad it's not supported, Please wait for next version.");
|
|
51
|
+
} else {
|
|
52
|
+
// help for see avaliable command
|
|
53
|
+
this.help()
|
|
54
|
+
.then(help => resolve(help))
|
|
55
|
+
.catch(err => reject(err));
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
reject(error);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
serviceDevStart(argument) {
|
|
64
|
+
logUpdate("[36mCompiling...[0m");
|
|
65
|
+
let promise = null;
|
|
66
|
+
// check Dev. run service
|
|
67
|
+
const spawnData = new Promise((resolve) => {
|
|
68
|
+
if(argument == "-D" || argument == "--dev") {
|
|
69
|
+
promise = this.spawn('npx', ['nodemon', '-q', './cli/beech']); // For Dev.
|
|
70
|
+
} else {
|
|
71
|
+
promise = this.spawn('npx', ['nodemon', '-q', './node_modules/beech-api/packages/cli/beech']); // For Prd.
|
|
72
|
+
}
|
|
73
|
+
resolve(promise.childProcess);
|
|
74
|
+
});
|
|
75
|
+
Promise.all([spawnData]).then((childProcess) => {
|
|
76
|
+
childProcess[0].stdout.on('data', (data) => {
|
|
77
|
+
console.log(data.toString().slice(0, -1));
|
|
78
|
+
});
|
|
79
|
+
childProcess[0].stderr.on('data', (data) => {
|
|
80
|
+
if(data.toString().slice(0, 8) != "Ignoring" && data.toString().match(/\[SEQUELIZE0006\]/g) != "[SEQUELIZE0006]") {
|
|
81
|
+
console.log(data.toString());
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
notiCompile() {
|
|
88
|
+
notifier.notify({
|
|
89
|
+
title: 'Beech API',
|
|
90
|
+
subtitle: 'Beech service getting started.',
|
|
91
|
+
message: "Service getting started.",
|
|
92
|
+
sound: 'Funk',
|
|
93
|
+
wait: false,
|
|
94
|
+
icon: path.join(__dirname, "/../../public/icon/beech_128.png"),
|
|
95
|
+
contentImage: path.join(__dirname, "../../public/icon/beech_128.png"),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
help() {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
try {
|
|
102
|
+
this.fs.readFile(__dirname + "/../core/generator/_help_service", "utf8", (err, data) => {
|
|
103
|
+
if (err) {
|
|
104
|
+
reject(err);
|
|
105
|
+
} else {
|
|
106
|
+
resolve(data);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
} catch (error) {
|
|
110
|
+
reject(error);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
embed(argv) {
|
|
116
|
+
return new Promise((resolve, reject) => {
|
|
117
|
+
try {
|
|
118
|
+
this.fs = require("fs");
|
|
119
|
+
this.spawn = require('child-process-promise').spawn;
|
|
120
|
+
this.argv = argv;
|
|
121
|
+
this.option = argv[ 2 ]; // serve|build
|
|
122
|
+
this.argument = argv[ 3 ]; // --silent -S | --dev -D
|
|
123
|
+
this.configFile = path.resolve("./app.config.js");
|
|
124
|
+
this._config_ = require(this.configFile);
|
|
125
|
+
resolve(this);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
reject(error);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
new Beech();
|
|
@@ -7,50 +7,91 @@ module.exports = {
|
|
|
7
7
|
// error check
|
|
8
8
|
if (err) {
|
|
9
9
|
console.log(err, info);
|
|
10
|
-
return
|
|
10
|
+
return res.status(401).json({
|
|
11
|
+
code: 401,
|
|
12
|
+
error: "UNAUTHORIZED",
|
|
13
|
+
message: {
|
|
14
|
+
name: "WrongTokenError",
|
|
15
|
+
message: "token error."
|
|
16
|
+
},
|
|
17
|
+
/* dev: { err, info } */ // for dev info
|
|
18
|
+
});
|
|
11
19
|
}
|
|
12
20
|
// anything token check
|
|
13
21
|
if (!user) {
|
|
14
|
-
if
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
22
|
+
if(info) {
|
|
23
|
+
if (info.name == 'TokenExpiredError') {
|
|
24
|
+
return res.status(401).json({
|
|
25
|
+
code: 401,
|
|
26
|
+
status: 'TOKEN_EXPIRED',
|
|
27
|
+
message: info
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (info.name == 'Error') {
|
|
31
|
+
return res.status(401).json({
|
|
32
|
+
code: 401,
|
|
33
|
+
status: 'NO_AUTH_TOKEN',
|
|
34
|
+
message: {
|
|
35
|
+
name: 'NoTokenError',
|
|
36
|
+
message: 'No auth token'
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (info.name == 'SyntaxError') {
|
|
41
|
+
return res.status(401).json({
|
|
42
|
+
code: 401,
|
|
43
|
+
status: 'PAYLOAD_SYNTAX_ERROR',
|
|
44
|
+
message: {
|
|
45
|
+
name: 'SyntaxError',
|
|
46
|
+
message: 'Unexpected token < in JSON at position 0'
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
return res.status(401).json({
|
|
45
52
|
code: 401,
|
|
46
|
-
status: '
|
|
47
|
-
error: 'UNAUTHORIZED_USER',
|
|
53
|
+
status: 'UNAUTHORIZED_USER',
|
|
48
54
|
message: info
|
|
49
55
|
});
|
|
50
56
|
}
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
// Check application key allow
|
|
58
|
+
const p1 = new Promise((resolve) => {
|
|
59
|
+
if (_passport_config_.app_key_allow) {
|
|
60
|
+
if (req.headers.app_key) {
|
|
61
|
+
if (_config_.main_config.app_key == req.headers.app_key) {
|
|
62
|
+
resolve(true);
|
|
63
|
+
} else {
|
|
64
|
+
res.status(401).json({
|
|
65
|
+
code: 401,
|
|
66
|
+
status: "BAD_REQUEST",
|
|
67
|
+
message: "Unauthorized with wrong key."
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
res.status(422).json({
|
|
72
|
+
code: 422,
|
|
73
|
+
status: "BAD_ENTIRY",
|
|
74
|
+
message: "Unprocessable Entity."
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
resolve(true);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
Promise.all([p1]).then((passed) => {
|
|
82
|
+
if(passed) {
|
|
83
|
+
// Forward user information to the next middleware
|
|
84
|
+
req.user = user;
|
|
85
|
+
next();
|
|
86
|
+
} else {
|
|
87
|
+
// When wrong all case above.
|
|
88
|
+
res.status(401).json({
|
|
89
|
+
code: 401,
|
|
90
|
+
status: "ERR_UNAUTHORIZED_ENTIRY",
|
|
91
|
+
message: "Unauthorized with wrong key."
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
54
95
|
})(req, res, next);
|
|
55
96
|
}
|
|
56
97
|
}
|