jgloo 1.8.0 → 1.8.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/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ <a name="1.8.2"></a>
2
+
3
+ ## [1.8.2](https://github.com/zosma180/jgloo/compare/1.8.1...1.8.2) (2022-12-08)
4
+
5
+ ### Fixes
6
+
7
+ - Updated the package-lock to fix the security issues
8
+
9
+ ---
10
+
11
+ <a name="1.8.1"></a>
12
+
13
+ ## [1.8.1](https://github.com/zosma180/jgloo/compare/1.8.0...1.8.1) (2022-08-03)
14
+
15
+ ### Fixes
16
+
17
+ - Fixed the "delay" option that was applied incorrectly
18
+
19
+ ---
20
+
1
21
  <a name="1.8.0"></a>
2
22
 
3
23
  ## [1.8.0](https://github.com/zosma180/jgloo/compare/1.7.0...1.8.0) (2022-07-29)
@@ -22,7 +42,7 @@
22
42
 
23
43
  ## [1.6.1](https://github.com/zosma180/jgloo/compare/1.6.0...1.6.1) (2022-07-22)
24
44
 
25
- ### Bug Fixes
45
+ ### Fixes
26
46
 
27
47
  - Updated the package-lock to fix the security issues
28
48
 
@@ -42,7 +62,7 @@
42
62
 
43
63
  ## [1.5.2](https://github.com/zosma180/jgloo/compare/1.5.1...1.5.2) (2021-02-21)
44
64
 
45
- ### Bug Fixes
65
+ ### Fixes
46
66
 
47
67
  - Fixed the folder path with space characters
48
68
 
@@ -52,7 +72,7 @@
52
72
 
53
73
  ## [1.5.1](https://github.com/zosma180/jgloo/compare/1.5.0...1.5.1) (2021-02-17)
54
74
 
55
- ### Bug Fixes
75
+ ### Fixes
56
76
 
57
77
  - Fixed the folder path for Windows environment
58
78
 
@@ -152,7 +172,7 @@
152
172
 
153
173
  ## [1.0.3](https://github.com/zosma180/jgloo/compare/1.0.2...1.0.3) (2019-12-18)
154
174
 
155
- ### Bug Fixes
175
+ ### Fixes
156
176
 
157
177
  - Fixed child process remaining alive
158
178
 
@@ -172,7 +192,7 @@
172
192
 
173
193
  ## [1.0.1](https://github.com/zosma180/jgloo/compare/1.0.0...1.0.1) (2019-12-16)
174
194
 
175
- ### Bug Fixes
195
+ ### Fixes
176
196
 
177
197
  - Fixed nodemon path
178
198
 
package/jgloo.js CHANGED
@@ -24,7 +24,7 @@ module.exports = {
24
24
 
25
25
  getDelayMiddleware: (delay) => {
26
26
  return (_, __, next) => {
27
- setTimeout(() => next(), delay * 1000);
27
+ setTimeout(next, delay * 1000);
28
28
  };
29
29
  },
30
30
  }
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ path: '/user',
3
+ method: 'post',
4
+ delay: 5,
5
+ callback: (req, res) => {
6
+ res.json({ testo: 'ciao 1' });
7
+ },
8
+ };
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ path: '/user',
3
+ method: 'get',
4
+ callback: (req, res) => {
5
+ res.json({ testo: 'ciao 2' });
6
+ },
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jgloo",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "The coldest mock server.",
5
5
  "homepage": "https://github.com/zosma180/jgloo",
6
6
  "repository": {
package/rest.js CHANGED
@@ -2,14 +2,14 @@ const path = require('path');
2
2
  const { getResource, setResource } = require(path.join(__dirname, 'jgloo'));
3
3
 
4
4
  module.exports = {
5
- configureResource: (app, config) => {
5
+ configureResource: (app, config, middleware) => {
6
6
  const fallback = config.path.split('/').filter(Boolean).join('-');
7
7
  const resourceName = config.name || fallback;
8
8
  const skips = config.not || [];
9
9
 
10
10
  // List
11
11
  if (skips.includes('LIST') === false) {
12
- app.get(config.path, (req, res) => {
12
+ app.get(config.path, middleware, (req, res) => {
13
13
  const resource = getResource(resourceName) || [];
14
14
  res.json(resource);
15
15
  });
@@ -17,7 +17,7 @@ module.exports = {
17
17
 
18
18
  // Read
19
19
  if (skips.includes('READ') === false) {
20
- app.get(`${config.path}/:id`, (req, res) => {
20
+ app.get(`${config.path}/:id`, middleware, (req, res) => {
21
21
  const id = Number(req.params.id);
22
22
 
23
23
  const resource = getResource(resourceName) || [];
@@ -30,7 +30,7 @@ module.exports = {
30
30
 
31
31
  // Create
32
32
  if (skips.includes('CREATE') === false) {
33
- app.post(config.path, (req, res) => {
33
+ app.post(config.path, middleware, (req, res) => {
34
34
  const resource = getResource(resourceName) || [];
35
35
  const model = req.body;
36
36
 
@@ -44,7 +44,7 @@ module.exports = {
44
44
 
45
45
  // Update
46
46
  if (skips.includes('UPDATE') === false) {
47
- app.put(`${config.path}/:id`, (req, res) => {
47
+ app.put(`${config.path}/:id`, middleware, (req, res) => {
48
48
  const id = Number(req.params.id);
49
49
 
50
50
  const resource = getResource(resourceName) || [];
@@ -61,7 +61,7 @@ module.exports = {
61
61
 
62
62
  // Patch
63
63
  if (skips.includes('PATCH') === false) {
64
- app.patch(`${config.path}/:id`, (req, res) => {
64
+ app.patch(`${config.path}/:id`, middleware, (req, res) => {
65
65
  const id = Number(req.params.id);
66
66
 
67
67
  const resource = getResource(resourceName) || [];
@@ -78,7 +78,7 @@ module.exports = {
78
78
 
79
79
  // Delete
80
80
  if (skips.includes('DELETE') === false) {
81
- app.delete(`${config.path}/:id`, (req, res) => {
81
+ app.delete(`${config.path}/:id`, middleware, (req, res) => {
82
82
  const id = Number(req.params.id);
83
83
 
84
84
  let resource = getResource(resourceName) || [];
package/server.js CHANGED
@@ -76,16 +76,16 @@ if (!api.length) {
76
76
 
77
77
  api.forEach(config => {
78
78
  // Add the API delay, if it is provided
79
- if (config.delay) {
80
- app.use(config.path, getDelayMiddleware(config.delay));
81
- }
79
+ const middleware = config.delay
80
+ ? getDelayMiddleware(config.delay)
81
+ : (_, __, next) => next();
82
82
 
83
83
  if (config.method === 'resource') {
84
84
  // ReST resource
85
85
  configureResource(app, config);
86
86
  } else {
87
87
  // Custom endpoint
88
- app[config.method](config.path, config.callback);
88
+ app[config.method](config.path, middleware, config.callback);
89
89
  }
90
90
  });
91
91