jgloo 1.6.1 → 1.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/CHANGELOG.md +10 -0
- package/package.json +1 -1
- package/server.js +23 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
<a name="1.7.0"></a>
|
|
2
|
+
|
|
3
|
+
## [1.7.0](https://github.com/zosma180/jgloo/compare/1.6.1...1.7.0) (2022-07-28)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Added the support for the recursive folder loading (api and middlewares)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
1
11
|
<a name="1.6.1"></a>
|
|
2
12
|
|
|
3
13
|
## [1.6.1](https://github.com/zosma180/jgloo/compare/1.6.0...1.6.1) (2022-07-22)
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
-
const { existsSync, readdirSync } = require('fs');
|
|
2
|
+
const { existsSync, readdirSync, lstatSync } = require('fs');
|
|
3
3
|
const express = require('express');
|
|
4
4
|
const cors = require('cors');
|
|
5
5
|
const bodyParser = require('body-parser');
|
|
@@ -22,6 +22,22 @@ if (!existsSync(root)) {
|
|
|
22
22
|
process.exit(2);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// Utility to deep load files
|
|
26
|
+
const walk = (entry, level = 1) => {
|
|
27
|
+
let list = [];
|
|
28
|
+
const items = readdirSync(entry);
|
|
29
|
+
|
|
30
|
+
items.forEach(item => {
|
|
31
|
+
const subEntry = path.join(entry, item);
|
|
32
|
+
|
|
33
|
+
lstatSync(subEntry).isDirectory() && level < 10
|
|
34
|
+
? list = list.concat(walk(subEntry, level + 1))
|
|
35
|
+
: list.push(subEntry);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return list;
|
|
39
|
+
};
|
|
40
|
+
|
|
25
41
|
// Config
|
|
26
42
|
app.use(cors());
|
|
27
43
|
app.use(bodyParser.json());
|
|
@@ -29,10 +45,10 @@ app.use(multer({ dest: staticPath }).any());
|
|
|
29
45
|
|
|
30
46
|
// Add middlewares
|
|
31
47
|
if (existsSync(middlewarePath)) {
|
|
32
|
-
|
|
33
|
-
.filter(
|
|
34
|
-
.forEach(
|
|
35
|
-
const middleware = require(
|
|
48
|
+
walk(middlewarePath)
|
|
49
|
+
.filter(file => file.endsWith('.js'))
|
|
50
|
+
.forEach(file => {
|
|
51
|
+
const middleware = require(file);
|
|
36
52
|
app.use(middleware);
|
|
37
53
|
});
|
|
38
54
|
}
|
|
@@ -48,7 +64,7 @@ if (!existsSync(apiPath)) {
|
|
|
48
64
|
process.exit(2);
|
|
49
65
|
}
|
|
50
66
|
|
|
51
|
-
const api =
|
|
67
|
+
const api = walk(apiPath).filter(file => file.endsWith('.js') );
|
|
52
68
|
|
|
53
69
|
if (!api.length) {
|
|
54
70
|
console.error(`No API file defined. Create one.`);
|
|
@@ -56,7 +72,7 @@ if (!api.length) {
|
|
|
56
72
|
}
|
|
57
73
|
|
|
58
74
|
api.forEach((file) => {
|
|
59
|
-
const config = require(
|
|
75
|
+
const config = require(file);
|
|
60
76
|
|
|
61
77
|
// Add the API delay, if it is provided
|
|
62
78
|
if (config.delay) {
|